Try this...
Sub Test2()
Dim Accts As Variant, Data As Variant, Results() As Double
Dim d1 As Date, d2 As Date
Dim i As Long, j As Long
With Sheets("Data")
Data = .Range("A5", .Range("A" & Rows.Count).End(xlUp)).Resize(, 9).Value
End With
With Sheets("Balance")
Accts = .Range("B8", .Cells(Rows.Count, "B").End(xlUp)).Value
ReDim Results(1 To UBound(Accts, 1), 1 To 2)
d1 = .Range("B3").Value
d2 = .Range("B4").Value
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For i = 1 To UBound(Accts, 1)
.Item(Accts(i, 1)) = i
Next i
For i = 1 To UBound(Data, 1)
If .Exists(Data(i, 2)) Then
If Data(i, 1) >= d1 And Data(i, 1) <= d2 Then
j = .Item(Data(i, 2))
If Data(i, 8) <> "" Then Results(j, 1) = Results(j, 1) + Data(i, 8)
If Data(i, 9) <> "" Then Results(j, 2) = Results(j, 2) + Data(i, 9)
End If
End If
Next i
End With
.Range("E8:F8").Resize(UBound(Results, 1)).Value = Results
End With
End Sub
Bookmarks