I'm working with an order report that lists every item on an order on a new line. I need to mail merge to a summary report that will have all the items on one sheet of paper. I've set up this macro to merge all the Item Numbers, Item Names, and Quantities ordered all onto one row, deleting the rows once they've been merged. It is working pretty well so far BUT if columns 15 (which is "O"), Row 4 happens to be the same quantity as O5, it deletes the first quantity. The same thing happens in Column N. No other duplicate in those columns have been deleted - just the first row (which is row 4). Column M, which is the item number of the ordered product, does not have the same issue. Even if the first two rows have the same item number, they are both retained. It's only happening for the first two rows of N and O that are causing the problem. Columns M, N, and O are the ones that I need to retail all the info. "A" is the only other column that has data in every row of the report. The other columns only have data in the initial row for each contract. Hope that makes sense. It looks something like this:
CONTRACT RESERVATION DATE ,etc until row M ITEMNUM ITEMNAME QTY
517027 176704 4/28/23 2745 Yellow Shirt 4
517027 5478 Blue Shirt 4
517027 7458 Green Hat 5
547512 178562 4/29/23 8745 Frosted Cake 1
547512 4756 Boiled Egg 6
This is the code I am working with. I did not write this - I copied after googling how to achieve my outcome and stumbled around personalizing it until I got it to (mostly) work.
Can you help me figure out how to stop deleting the first two duplicates?
Any help would be appreciated!
CONTRACT RESERVATION DATE ,etc until row M ITEMNUM ITEMNAME QTY
517027 176704 4/28/23 2745 Yellow Shirt 4
517027 5478 Blue Shirt 4
517027 7458 Green Hat 5
547512 178562 4/29/23 8745 Frosted Cake 1
547512 4756 Boiled Egg 6
This is the code I am working with. I did not write this - I copied after googling how to achieve my outcome and stumbled around personalizing it until I got it to (mostly) work.
Can you help me figure out how to stop deleting the first two duplicates?
Any help would be appreciated!
VBA Code:
Sub Pulling Report ()
Dim myRow As Long
Dim sTRef As String
sTRef = Cells(2, "a")
myRow = 4
Do While Cells(myRow, "a") <> ""
If sTRef <> Cells(myRow, "a") Then
sTRef = Cells(myRow, "a")
myRow = myRow + 1
Else
For i = 1 To 16
If Cells(myRow - 1, i) = "" Then
Cells(myRow - 1, i) = Cells(myRow, i)
Else
If Cells(myRow, i) = Cells(myRow - 1, i) Then
Cells(myRow - 1, i) = Cells(myRow, i)
Else
If Cells(myRow, i) <> "" Then
Cells(myRow - 1, i) = Cells(myRow - 1, i) & vbNewLine & Cells(myRow, i)
End If
End If
End If
Next i
rows(myRow).Delete Shift:=xlUp
End If
Loop
rows(1).EntireRow.Delete
rows(2).EntireRow.Delete
Range("A1").Value = "CONTRACT"
Range("b1").Value = "RESERVATION"
Range("C1").Value = "OUTDATE"
Range("D1").Value = "INDATE"
Range("E1").Value = "NAME"
Range("F1").Value = "JOBNAME"
Range("G1").Value = "ADDY1"
Range("H1").Value = "ADDY2"
Range("I1").Value = "CITY"
Range("J1").Value = "STATE"
Range("K1").Value = "ZIP"
Range("L1").Value = "POJOB"
Range("P1").Value = "ITEMS"
End Sub
Last edited by a moderator: