Hello Guys!
I need little help with my script. It compares A2:A from two Sheets and if match it is copying cell F of one shhet to cell K of the other.
It works fine But...
I want to compare not only A2:A but A2:A and Offset(,3) to Offset(,4)
something like
My working Macro
Or mayby it can be done better (faster - I have over 1M rows n one sheet and aboput 50K i second)
Best Regards!
W.
I need little help with my script. It compares A2:A from two Sheets and if match it is copying cell F of one shhet to cell K of the other.
It works fine But...
I want to compare not only A2:A but A2:A and Offset(,3) to Offset(,4)
something like
Code:
Kl.Value & Kl.Offset(,3)
to
K2.Value & K2.Offset(,4)
My working Macro
Code:
Dim Kl As Range, K2 As Range
Dim ValK As Variant, ValK2 As Variant
Dim dict As Scripting.Dictionary, dict2 As Scripting.Dictionary
Set dict = New Scripting.Dictionary
dict.CompareMode = vbTextCompare
Set dict2 = New Scripting.Dictionary
dict2.CompareMode = vbTextCompare
With dict
For Each Kl In Sheets(1).Range("A2", Sheets(1).Range("A" & Rows.count).End(xlUp))
If Not .Exists(Kl.Value) Then .Add Kl.Value, Kl.row
Next Kl
End With
With dict2
For Each K2 In Sheets(2).Range("A2", Sheets(2).Range("A" & Rows.count).End(xlUp))
If Not .Exists(K2.Value) Then .Add K2.Value, K2.row
Next K2
End With
For Each ValK In dict.keys
For Each ValK2 In dict2.keys
If ValK Like ValK2 Then
With Sheets(1)
.Cells(dict(ValK), "K").Value = Sheets(2).Range("F" & dict2(ValK2))
End With
End If
Next ValK2
Next ValK
Or mayby it can be done better (faster - I have over 1M rows n one sheet and aboput 50K i second)
Best Regards!
W.
Last edited: