Check this
Sub INTERST()
Dim D As Object
Dim i As Long
Set D = CreateObject("scripting.dictionary")
'Filling Dictionary object with unique values and their Data
With Sheets("Data")
For i = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
If Not D.exists(CStr(Cells(i, 2).Value)) Then
D.Add CStr(Cells(i, 2).Value), CStr(Cells(i, 3).Value) & "-" & Cells(i, 4).Value
Else
D.Item(CStr(Cells(i, 2).Value)) = D.Item(CStr(Cells(i, 2).Value)) & "," & Cells(i, 3).Value & "-" & Cells(i, 4).Value
End If
Next
End With
'Now Retrieval
With Sheets("Result")
For j = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
Tmp = Split(D.Item(CStr(.Cells(j, 1).Value)), ",") 'Get Each dictionary value Data and split it with ","
If InStr(.Cells(j, 2), "|") > 0 Then
Tmp2 = Split(.Cells(j, 2), "|") 'Split second column Text for looping array Ex:2|4
LT = Tmp2(0) 'Lower bound of array
Ht = Tmp2(1) 'Higer bound of array
For k = LT - 1 To Ht - 1
Txt = Txt & Split(Tmp(k), "-")(1)
Next
.Cells(j, 4) = "(" & Txt & ") (" & Application.WorksheetFunction.VLookup(.Cells(j, 1).Value, Sheets("data").Range("F:G"), 2, 0) & " " & .Cells(j, 2).Value & ")"
Else
.Cells(j, 4) = "(" & Split(Tmp(0), "-")(1) & ") (" & Application.WorksheetFunction.VLookup(.Cells(j, 1).Value, Sheets("data").Range("F:G"), 2, 0) & " " & .Cells(j, 2).Value & ")"
End If
Txt = ""
Next
End With
MsgBox "Hey I have done my work"
End Sub
'Made by :- Mandeep baluja
'https://www.facebook.com/groups/825221420889809/
'https://www.linkedin.com/in/mandeep-baluja-b777bb88
Add Reputation if it helped
Bookmarks