Sub demo()
'[e2:e1000].ClearContents
Set d = CreateObject("Scripting.Dictionary")
a = Sheets(1).UsedRange
For i = 2 To UBound(a)
If d.exists(a(i, 2)) Then a(i, 5) = a(i, 3) - d(a(i, 2))
d(a(i, 2)) = a(i, 3)
Next
[a1].Resize(UBound(a), UBound(a, 2)) = a
End Sub
Sub demo()
'[e2:e1000].ClearContents
Set d = CreateObject("Scripting.Dictionary")
a = Sheets(1).UsedRange
For i = 2 To UBound(a)
If d.exists(a(i, 2)) Then a(i, 5) = a(i, 3) - d(a(i, 2))
d(a(i, 2)) = a(i, 3)
Next
[a1].Resize(UBound(a), UBound(a, 2)) = a
End Sub