Set dic = CreateObject("scripting.dictionary")
Set dic2 = CreateObject("scripting.dictionary")
This creates 2 dictionaries (some sort of containers)
With Sheet4
sn = .Range("A3", .Range("A" & .Rows.Count).End(xlUp)).Resize(, 2)
End With
For i = 1 To UBound(sn)
If sn(i, 1) = 4 Then x0 = dic.Item(sn(i, 2))
Next
This puts the values of Column A & B from Jan-sheet into an array and loops all values.
When there's a 4 in column A it' puts the corresponding value of Column B into the first dictionary (dic )
With Sheet1
sn = .Range("A2", .Range("A" & .Rows.Count).End(xlUp)).Resize(, 2)
End With
For i = 1 To UBound(sn)
If sn(i, 1) = 4 Then x0 = dic2.Item(sn(i, 2))
Next
This does the same but for december sheet (dic2)
For Each Key In dic.keys
If dic2.exists(Key) Then dic.Remove (Key)
Next
This compares every element from the 1st dictionary (dic) with the second dictionary (dic2)
If there's a match then the value gets deleted from the 1 dictionary (dic)
Sheet4.Cells(3, 8).Resize(dic.Count) = Application.Transpose(dic.keys)
This puts the remaining values in 1st dictionary (dic) onto your worksheet.
Bookmarks