Try
Sub test()
Dim a, i As Long, x As Range, dic As Object
Set dic = CreateObject("Scripting.Dictionary")
dic.CompareMode = 1
a = Sheets("expected coding charges code").Cells(1).CurrentRegion.Value
For i = 1 To UBound(a, 1)
dic(a(i, 1) & ";" & a(i, 2)) = Empty
Next
With Sheets("workings")
.Range("al2").CurrentRegion.Clear
For i = .Range("f" & Rows.Count).End(xlUp).Row To 1 Step -1
If dic.exists(.Cells(i, "f").Value & ";" & .Cells(i, "g").Value) Then
If x Is Nothing Then
Set x = Union(.Range("f" & i).Resize(, 2), .Range("aa" & i))
Else
Set x = Union(x, Union(.Range("f" & i).Resize(, 2), .Range("aa" & i)))
End If
Else
Exit For
End If
Next
If Not x Is Nothing Then
x.Copy .Range("al2")
.Range("an1").Value = "Amount"
.Range("an" & Rows.Count).End(xlUp)(2).FormulaR1C1 = "=sum(r2c:r[-1]c)"
.Range("al2").CurrentRegion.Borders.Weight = 2
x.EntireRow.Clear
End If
End With
End Sub
Bookmarks