Assuming:
1) Data starts in row1
2) Columns A:C only are used
Try this on a copy of your data, it uses columns E:H to quickly make a unique match table:
Option Explicit
Sub LineEmUp3()
'Column A matched to partial strings in column B then lined up accordingly
Dim LR As Long
Application.ScreenUpdating = False 'speed up macro
LR = Range("A" & Rows.Count).End(xlUp).Row 'last used row in column A
LR = WorksheetFunction.Max(LR, Range("B" & Rows.Count).End(xlUp).Row) 'last used row in column B, take the max
Range("F1") = "Key" 'title of temp filter column
Range("A1:A" & LR).Copy Range("F2") 'copy column A into column F
Range("B1:B" & LR).Copy Range("F" & Rows.Count).End(xlUp).Offset(1) 'add column B to column F
'remove the word " Count" from column F
Columns("F:F").Replace What:=" Count", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
'take unique values from F and put in column E
Range("F:F").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("E1"), Unique:=True
Columns("F:F").ClearContents 'clear column F
LR = Range("E" & Rows.Count).End(xlUp).Row 'last used row in column E
'formula to match A to the new column E
Range("F2:F" & LR).FormulaR1C1 = "=IF(ISNUMBER(MATCH(RC5,C[-5], 0)), RC5, """")"
'formula to match B to the new column E
Range("G2:G" & LR).FormulaR1C1 = "=IF(ISNUMBER(MATCH(RC5&""*"",C[-5], 0)), RC5 & "" Count"", """")"
'Vlookup to bring over quantities from column C
Range("H2:H" & LR).FormulaR1C1 = "=IF(RC[-1]="""", """", VLOOKUP(RC[-1], C2:C3, 2, 0))"
Range("F2:H" & LR).Copy 'paste the new table from F:H back over A:C
Range("A1").PasteSpecial xlPasteValues
Range("E:H").ClearContents 'clear F:H
Application.ScreenUpdating = True 'back to normal speed
End Sub
Bookmarks