Hello Guys!
Can You help me refactor this code to be more noobie frendly? Or it is good as it is? (code is not mine and I bearly understand it)
It looks for the same values in two sheets and if match it copy value from other column of found row to yet another column of searching row.
Thank You!
W.
Can You help me refactor this code to be more noobie frendly? Or it is good as it is? (code is not mine and I bearly understand it)
It looks for the same values in two sheets and if match it copy value from other column of found row to yet another column of searching row.
Code:
Dim Kl As Range, K2 As Range
Dim ValK As Variant, ValK2 As Variant
Dim dict As Scripting.Dictionary, dict2 As Scripting.Dictionary
Dim ar_2 As Long, ar_1 As Long
Dim new_DG As String, new_DI As String
Set dict = New Scripting.Dictionary
dict.CompareMode = vbTextCompare
Set dict = CreateObject("Scripting.Dictionary")
With dict
For Each Kl In Sheets(7).Range("A2", Sheets(7).Range("A" & Rows.count).End(xlUp))
ValK = Kl.Value
ar_2 = Kl.row
If Not .Exists(ValK) Then .Add ValK, ar_2
Next Kl
End With
Set dict2 = New Scripting.Dictionary
dict2.CompareMode = vbTextCompare
Set dict2 = CreateObject("Scripting.Dictionary")
With dict2
For Each K2 In Sheets(4).Range("f2", Sheets(4).Range("F" & Rows.count).End(xlUp))
ValK2 = K2.Value
ar_1 = K2.row
If Not .Exists(ValK2) Then .Add ValK2, ar_1
Next K2
End With
For Each ValK In dict.keys
For Each ValK2 In dict2.keys
If ValK = ValK2 Then
new_DG = Sheets(4).Range("DG" & dict2(ValK2))
new_DI = Sheets(4).Range("DI" & dict2(ValK2))
With Sheets(7)
.Cells(dict(ValK), "M").Value = new_DG
.Cells(dict(ValK), "N").Value = new_DI
End With
End If
Next ValK2
Next ValK
Thank You!
W.