If the output cell has more than 255 characters, Transpose function will fail.
Try this one
Sub test()
Dim a, b(), i As Long, txt As String, w, maxCol As Long, n As Long
With Range("a1").CurrentRegion
a = .Value
ReDim Preserve a(1 To UBound(a, 1), 1 To 100)
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For i = 1 To UBound(a, 1)
If a(i, 3) <> "" Then
txt = a(i, 1)
If Not .exists(txt) Then
n = n + 1
a(n, 1) = a(i, 1)
a(n, 2) = a(i, 2)
a(n, 3) = a(i, 3)
.Item(txt) = VBA.Array(n, 3)
Else
w = .Item(txt)
w(1) = w(1) + 2
If UBound(a, 2) < w(1) Then
ReDim Preserve a(1 To UBound(a, 1), 1 To UBound(a, 2) + 100)
End If
a(w(0), w(1) - 1) = a(i, 2)
a(w(0), w(1)) = a(i, 3)
.Item(txt) = w
maxCol = Application.Max(maxCol, w(1))
End If
End If
Next
End With
With .Offset(, .Columns.Count + 3).Resize(n, maxCol)
.CurrentRegion.ClearContents
.Value = a
If maxCol + 1 > 3 Then
With .Offset(, 1).Resize(1, 2)
.AutoFill .Resize(, maxCol - 1)
End With
End If
.Columns.AutoFit
End With
End With
End Sub
Bookmarks