Option Explicit
Sub TinhTienTheoLop()
Dim Cls As Range, WF As Object, CSDL As Range, sRng As Range, dRg As Range
Dim MyAdd As String
Set WF = Application.WorksheetFunction
Set CSDL = Range([A5], [A5].End(xlDown))
Set sRng = CSDL.Find("GPE", , xlFormulas, xlPart)
Set dRg = Rows("65525:65525")
If Not sRng Is Nothing Then
MyAdd = sRng.Address
Do
Set dRg = Union(dRg, sRng.EntireRow)
Set sRng = CSDL.FindNext(sRng)
Loop While Not sRng Is Nothing And sRng.Address <> MyAdd
End If
dRg.Delete
Set CSDL = [b5].CurrentRegion
For Each Cls In Range([AA5], [AA5].End(xlDown))
[ac5].Value = Cls.Value
With [A65500].End(xlUp).Offset(1)
.Value = Cls.Value & "GPE": .Offset(, 2).Value = [AA1].Value
Randomize
.Interior.ColorIndex = 34 + 9 * Rnd \ 1
.Offset(, 7).Value = WF.DSum(CSDL, [H4], [Ac4:AC5])
End With
Next Cls
[b5].CurrentRegion.Sort Key1:=Range("A5"), Order1:=xlAscending, Key2:=Range("B5") _
, Order2:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:=False _
, Orientation:=xlTopToBottom
End Sub