Give this a try
Option Explicit
Sub abc()
Const sh1 As String = "sheet1"
Const sh2 As String = "sheet2"
Dim a, k, x, i As Long, n As Long
With Worksheets(sh1)
a = .Range("a1").CurrentRegion
End With
With CreateObject("scripting.dictionary")
.comparemode = 1
For i = 2 To UBound(a)
If Not .exists(a(i, 2)) Then
.Item(a(i, 2)) = a(i, 1)
Else
.Item(a(i, 2)) = Join(Array(.Item(a(i, 2)), a(i, 1)), "|")
End If
Next
a = .items
k = .keys
End With
With Worksheets(sh2)
.Cells.Delete
With .Cells(Rows.Count, 1).End(xlUp)
For i = 0 To UBound(a)
x = Application.Transpose(Split(a(i), "|"))
With .Offset(, n)
.Value = k(i)
.Font.Bold = True
End With
With .Offset(1, n).Resize(UBound(x))
.Value = x
.Columns.EntireColumn.AutoFit
End With
n = n + 2
Next
End With
End With
End Sub
Bookmarks