Hi Rabid Squirrel
No problem, almost perfectly is not close enough
Option Explicit
Sub test19()
Dim a, b(), i As Long, ii As Long, n As Long, temp As String, e
With Worksheets("Sheet1").Range("a1", Range("a" & Rows.Count).End(xlUp)).Resize(, 5)
a = .Value
End With
ReDim b(1 To UBound(a, 1), 1 To 5)
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
For i = 1 To UBound(a, 1)
If Not IsEmpty(Trim(a(i, 1))) Then
If Not .exists(Trim(a(i, 1))) Then
n = n + 1
For ii = 1 To 5
b(n, ii) = Trim(a(i, ii))
Next
.Add Trim(a(i, 1)), n
Else
For ii = 2 To 5
b(.Item(Trim(a(i, 1))), ii) = b(.Item(Trim(a(i, 1))), ii) & IIf(b(.Item(Trim(a(i, 1))), ii) <> "", ",", "") & " " & a(i, ii)
Next
End If
End If
Next
.RemoveAll
For i = 2 To n
For ii = 2 To 5
For Each e In Split(b(i, ii), ",")
If Not .exists(Trim(e)) Then
temp = temp & "," & e
.Add Trim(e), Nothing
End If
Next
b(i, ii) = Mid$(temp, 2)
temp = ""
.RemoveAll
Next
Next
End With
With Worksheets("Sheet3")
.Range("a1").Resize(n, 5).Value = b
End With
Bookmarks