Hi
Say your data is in columns A and B, with A1 and B1 as headings.
In a general module, insert the code
Sub aaa()
Range("D:H").ClearContents
For Each ce In Range("B2:B11")
strr = myfunc(ce.Offset(0, -1).Value, Range("B:B")) & "," & ce.Value
arr = Split(strr, ",")
outrow = Cells(Rows.Count, "D").End(xlUp).Offset(1, 0).Row
outcol = 4
For i = LBound(arr) To UBound(arr)
Cells(outrow, outcol) = arr(i)
outcol = outcol + 1
Next i
Next ce
lastrow = Cells(Rows.Count, "D").End(xlUp).Row
Range("D2:J" & lastrow).Sort key1:=Range("D2"), order1:=xlAscending, key2:=Range("E2"), order2:=xlAscending
End Sub
Function myfunc(x, rng As Range)
If WorksheetFunction.CountIf(rng, x) = 0 Then
myfunc = x
Else
Set findit = rng.Find(what:=x)
myfunc = myfunc(findit.Offset(0, -1), rng) & "," & x
End If
End Function
I've assumed that the output starts in column D, and for the sake of testing, my data only nested to 4 levels, so I've cleared out columns D:H just to be sure before running.
See how this goes for a start.
rylo
Bookmarks