Dim Cell As Range
Dim Data As Variant
Dim Dict As Object
Dim Item As Variant
Dim Key As Variant
Dim Rng As Range
Dim RngBeg As Range
Dim RngEnd As Range
Dim Wks As Worksheet
Set Wks = ThisWorkbook.activesheet
Set RngBeg = Wks.Range("A1:D8")
Set RngEnd = Wks.Cells(Rows.Count, RngBeg.Column).End(xlUp)
If RngEnd.Row < RngBeg.Row Then Exit Sub
Set Rng = Wks.Range(RngBeg, RngEnd)
Set Dict = CreateObject("Scripting.Dictionary")
Dict.CompareMode = vbTextCompare
For Each Cell In Rng.Columns(1).Cells
Key = Trim(Cell)
Item = Cell.Resize(1, Rng.Columns.Count).Value
With activesheet
For Each Cell In .Range("k2", .Range("k" & Rows.Count).End(xlUp))
If Dict.exists(Cl.Value) Then Cell.Offset(, 1).Value = Dic(Cell.Value)
Next Cell
End With
In column K I have values : 98,34,78,11 and in column A I have :98,98,98,11,34,78,78
The dictionary stores each row in col A:D
for example:
98,east,phone,address
98,west,mobile,na
and then checks if the first cell in A1: 98 matches with column K and if it does paste row A1:D1 next to row in column K corresponding to 98 and insert a row if there several matches i.e 3 98s in column A.
The problem occurs here where it is supposed to paste the values next to the unique keys ie 98 in column K but does not do so:
With activesheet
For Each Cell In .Range("k2", .Range("k" & Rows.Count).End(xlUp))
If Dict.exists(Cell.Value) Then Cell.Offset(, 1).Value = Dic(Cell.Value)
Next Cell
End With
Could someone please suggest what is going wrong?
I have edited code referenced from here: