Try running this macro to reduce your data.
Sub Macro2()
'Find Your Last Row
LR = Cells(Rows.Count, 1).End(xlUp).Row
'Sort your Data by Order Number and then by Item
ActiveWorkbook.Worksheets("BEFORE").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("BEFORE").Sort.SortFields.Add2 Key:=Range( _
"A2:A" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("BEFORE").Sort.SortFields.Add2 Key:=Range( _
"B2:B" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("BEFORE").Sort
.SetRange Range("A1:B5" & LR)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'Enter a formula in Column C to find the maximum number of items on an order
With Range("C2:C" & LR)
.FormulaR1C1 = "=IF(RC[-2]<>R[-1]C[-2],1,R[-1]C+1)"
MaxItems = Application.Max(.Value)
End With
'Select the number of cells to put the formula to transpose your items into a horizontal line
DataRange = Range("C2", Cells(LR, MaxItems + 2)).Address
'Enter the formula to tanspose your data
With Range(DataRange)
.Formula2R1C1 = _
"=IF(OR(RC1=R[-1]C1,INDEX(RC1:R20000C1,COLUMN()-2,1)<>RC1),"""",INDEX(RC2:R20000C2,COLUMN()-2,1))"
.Value = .Value
End With
Columns(2).Delete
Rows(1).Delete
With Range("A1:A" & LR)
.FormulaR1C1 = "=TEXTJOIN("", "",TRUE,RC[1]:RC[" & MaxItems + 2 & "])"
.Value = .Value
End With
Columns("B:" & Split(Cells(1, MaxItems + 2).Address, "$")(1)).Delete
With Columns("A:A")
.Columns.AutoFit
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
ActiveWorkbook.Worksheets("BEFORE").Sort.SortFields.Add2 Key:=Range("A1"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("BEFORE").Sort
.SetRange Range("A1:A" & LR)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Bookmarks