Try
Option Explicit
Sub test()
Dim a, i As Long, ii As Long, w(), n As Long, txt As String
Dim AL As Object, e, s
Set AL = CreateObject("System.Collections.ArrayList")
n = 1
a = Range("a1").CurrentRegion.Value
txt = a(3, 4) & vbLf & a(2, 4)
With CreateObject("Scripting.Dictionary")
For i = 2 To UBound(a, 1) Step 2
If a(i, 1) = "" Then Exit For
If Not .exists(a(i, 1)) Then
ReDim w(2)
n = n + 1
w(0) = n
Set w(1) = _
CreateObject("Scripting.Dictionary")
w(2) = VBA.Array(a(i, 1), a(i, 2), a(i, 3))
.Item(a(i, 1)) = w
End If
w = .Item(a(i, 1))
For ii = 5 To UBound(a, 2)
If a(i, ii) <> "" Then
If Not AL.contains(a(i, ii)) Then
AL.Add a(i, ii)
End If
w(1)(a(i, ii)) = w(1)(a(i, ii)) + a(i + 1, ii)
End If
Next
.Item(a(i, 1)) = w
Next
AL.Sort
ReDim a(1 To n + 1, 1 To AL.Count + 4)
a(1, 1) = "SKU": a(1, 2) = "Item Description": a(1, 3) = "Size"
For i = 0 To AL.Count - 1
a(1, i + 4) = txt & AL(i)
Next
For Each e In .keys
w = .Item(e)
For i = 1 To 3
a(w(0), i) = w(2)(i - 1)
Next
For Each s In w(1).keys
For ii = 5 To UBound(a, 2)
a(w(0), AL.Indexof(s, 0) + 4) = w(1)(s)
Next
Next
Next
End With
With Range("a1").CurrentRegion
With .Offset(, .Columns.Count + 2)
.CurrentRegion.Clear
With .Resize(n, AL.Count + 3)
.Value = a
.ColumnWidth = 20
.Columns.AutoFit
.WrapText = True
.Borders.Weight = 2
End With
End With
End With
Set AL = Nothing
End Sub
TestWithCode.xlsm
Bookmarks