Sorry that was a typo, should be "exists"
You will need to adjust the array as per your real data layouts.
Sub test()
Dim a, i As Long, ii As Long, w, dic As Object
Set dic = CreateObject("Scripting.Dictionary")
a = Sheets("SOURCE SHEET").Cells(1).CurrentRegion.Value
For i = 2 To UBound(a, 1)
dic(a(i, 1)) = Array(a(i, 2), a(i, 3), a(i, 4), a(i, 5) + a(i, 6), a(i, 5) + a(i, 6))
Next
a = Sheets("SOURCE SHEET EXPENSES").Cells(1).CurrentRegion.Value
For i = 2 To UBound(a, 1)
If (dic.exists(a(i, 1))) * (a(i, 4) > 500) Then
w = dic(a(i, 1)): w(4) = w(4) - a(i, 4)
dic(a(i, 1)) = w
End If
Next
With Sheets("OUTPUT SHEET").Cells(1).CurrentRegion
.Offset(1, 1).ClearContents
a = .Value
For i = 2 To UBound(a, 1)
If dic.exists(a(i, 1)) Then
For ii = 2 To UBound(a, 2)
a(i, ii) = dic(a(i, 1))(ii - 2)
Next
End If
Next
.Value = a
End With
End Sub
Bookmarks