Sub test()
Dim a, i As Long, ii As Long, dic As Object
Set dic = CreateObject("Scripting.Dictionary")
a = Selection.Value
For i = 1 To UBound(a, 1)
If i > 1 Then
If a(i, 1) = "" Then a(i, 1) = a(i - 1, 1)
End If
If a(i, 2) <> "TOTAL" Then
If Not dic.exists(a(i, 1)) Then
dic(a(i, 1)) = dic.Count + 1
For ii = 1 To UBound(a, 2)
a(dic(a(i, 1)), ii) = a(i, ii)
Next
Else
a(dic(a(i, 1)), 3) = _
a(dic(a(i, 1)), 3) & ", " & a(i, 3)
For ii = 4 To UBound(a, 2)
a(dic(a(i, 1)), ii) = a(dic(a(i, 1)), ii) + a(i, ii)
Next
End If
End If
Next
With Sheets("sheet2").Cells(1).Resize(dic.Count, UBound(a, 2))
.CurrentRegion.Clear
.Value = a
.Borders.Weight = 2
.Columns.AutoFit
.Parent.Select
End With
End Sub
Bookmarks