First, you need to add a little "string concatentation" utility to your sheet to make this easier. And the macro that follows will do the work you wanted. It assumes there's nothing in columns C and D. If that won't work, let me know and we'll insert some blank columns first.
Press Alt-F11 to open the VBEditor
Click Insert > Module
Paste in all this code (function and macro)
Function ConcatIf(ByVal compareRange As Range, ByVal xCriteria As Variant, Optional ByVal stringsRange As Range, _
Optional Delimiter As String, Optional NoDuplicates As Boolean) As String
' code base by Mike Rickson, MrExcel MVP
' used as exactly like COUNTIF() with two additional parameters
' of delimiter and "no duplicates" as TRUE/FALSE if concatenated values
' might include duplicates ex. =ConcatIf($A$1:$A$10,C1,$B$1:$B$10,", ",True)
Dim i As Long, j As Long
With compareRange.Parent
Set compareRange = Application.Intersect(compareRange, Range(.UsedRange, .Range("a1")))
End With
If compareRange Is Nothing Then Exit Function
If stringsRange Is Nothing Then Set stringsRange = compareRange
Set stringsRange = compareRange.Offset(stringsRange.Row - compareRange.Row, _
stringsRange.Column - compareRange.Column)
For i = 1 To compareRange.Rows.Count
For j = 1 To compareRange.Columns.Count
If (Application.CountIf(compareRange.Cells(i, j), xCriteria) = 1) Then
If InStr(ConcatIf, Delimiter & CStr(stringsRange.Cells(i, j))) <> 0 Imp Not (NoDuplicates) Then
ConcatIf = ConcatIf & Delimiter & CStr(stringsRange.Cells(i, j))
End If
End If
Next j
Next i
ConcatIf = Mid(ConcatIf, Len(Delimiter) + 1)
End Function
Sub Consolidate()
Dim i As Integer, lastArow As Long, lastCrow As Long
lastArow = Range("A" & Rows.Count).End(xlUp).Row
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Range("A1:A" & lastArow).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("C1"), Unique:=True
Range("B1").Value = "Items"
lastCrow = Range("C" & Rows.Count).End(xlUp).Row
Range("D2:D" & lastCrow).FormulaR1C1 = "=concatif(R2C1:R9C1,RC[-1],R2C2:R9C2,"", "")"
Columns("D:D").Copy
Columns("D:D").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.EnableEvents = True
Application.Calculation = xlAutomatic
Calculate
Columns("A:B").Delete Shift:=xlToLeft
Range("C1").Select
End Sub
Press Alt-F11 to close the editor
Save your sheet.
Press Alt-F8 and run the "consolidate" macro.
Bookmarks