Hello. Could someone please explain each piece of this code? Someone recommended stepping through it, which I did, but that doesn't help you learn if you don't know what the stuff means. A lot of the code action is behind the scenes.
Code:
Sub transe()
Dim a, z, i As Long, j As Long, Y, n&, x, k, jj&
Const delim As String = ","
With Sheets("Sheet1")
a = .Range("A2").CurrentRegion
End With
With CreateObject("Scripting.Dictionary")
.comparemode = 1
ReDim Y(1 To UBound(a, 1), 1 To 2)
For i = 2 To UBound(a)
If Not .exists(a(i, 1)) Then
ReDim z(1 To UBound(a, 2))
For j = 1 To UBound(a, 2)
z(j) = a(i, j)
Next
.Item(a(i, 1)) = Join(z, delim)
Else
ReDim z(1 To UBound(a, 2))
For j = 2 To UBound(a, 2)
z(j) = a(i, j)
Next
.Item(a(i, 1)) = .Item(a(i, 1)) & "," & Join(z, delim)
End If
Next
z = .items
For i = 0 To UBound(z)
x = Split(z(i), delim)
n = n + 1
jj = 0
For k = 0 To UBound(x)
If x(k) <> vbNullString Then
If jj >= UBound(Y, 2) Then ReDim Preserve Y(1 To UBound(a, 1), 1 To jj + 1)
jj = jj + 1
Y(n, jj) = x(k)
End If
Next
Next
With Sheets("Sheet2")
.UsedRange.Offset(1).ClearContents
.Range("A2").Resize(n, UBound(Y, 2)) = Y
.Columns.AutoFit
End With
End With
End Sub