Clear cell data if rows match

muhleebbin

Active Member
Joined
Sep 30, 2017
Messages
252
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2010
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
Hi,

I have a data set from my website of customer orders, however I need to manipulate it so that it omits duplicate entries which is throwing off the pivot table calculations.

Basically column A has the order numbers and there are often times duplicate entries, column O has the amount paid but it is the same for both (sometimes multiple rows) so it accounts for the amount twice (or however many times it is repeated. Is it possible to make a macro that finds matching order numbers and then only keeping the first instance of the amount in Column O?

Hope this makes sense and thank you in advance for your help!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Sounds like you just need to remove duplicates.

VBA Code:
Sub RemoveDuplicates()
    ActiveSheet.Range("$A:$O").RemoveDuplicates Columns:=1, Header:=xlYes
End Sub
 
Upvote 0
Sounds like you just need to remove duplicates.

VBA Code:
Sub RemoveDuplicates()
    ActiveSheet.Range("$A:$O").RemoveDuplicates Columns:=1, Header:=xlYes
End Sub

There are a few instances where a duplicate is needed. Typically this would be the solution but there are a few instances where the customer purchases something for one day at one price and another day for another price but on the same transaction (i.e. $50 for June 4 $100 for June 5 for a total of $150). We still need to see the two individual transactions. But column O records $150 for each row so the pivottable thinks the amount collected is $300 rather than the true $150.
 
Upvote 0
Date is in Column D

Attached is some sample data. Sample Test and Test1-2 it would be fine to delete the extra rows but I'd prefer to keep the row and just remove the duplicate entry in column o. Test 3&4 are the cases where it would be ideal to keep the rows. As you can see in column U the unit price is different for each class that was registered for. That information is actually valuable for us.

Thanks!

ItemsSold_5-1-2021_to_5-31-2021 (1).xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAW
1Order IdReference IdDATEDate OnlyTime OnlyemailOrder Sub TotalShipping TotalTax TotalShipping Tax TotalOrder Items TaxOrder Discount TotalGrand TotalGift Card PaidAmount PaidCard TypeGift Card UsedProductCategory NameQuantityUnit PriceTotal Item PriceItem Shipping TotalItem Tax TotalItem DiscountItem Grand TotalEvent DateShipping NameShipping Address Line1Shipping Address Line2Shipping CityShipping StateShipping Postal CodeShipping PhoneBilling NameBilling Address Line1Billing Address Line2Billing CityBilling StateBilling Postal CodeBilling PhoneGift Card NumberSeries NameFrom NameTo NameTo EmailShip MethodCC Last FourNote
21207969Test05/30/2021 15:16:45 -07:00########15:16:45.2429765Test170000001700170VisaSpring Gnocchi | In Person ClassEventVouchers185850008506/18/2021 18:00:00 -07:00TestTestTestTestTestTestTestHot Stove Society Class VoucherTestTestTest
31207969Test05/30/2021 15:16:45 -07:00########15:16:45.2429765Test170000001700170VisaSpring Gnocchi | In Person ClassEventVouchers185850008506/18/2021 18:00:00 -07:00TestTestTestTestTestTestTestHot Stove Society Class VoucherTestTestTest
41207748Test105/29/2021 22:14:25 -07:00########22:14:25.7789511Test1250000002500250VisaHot Stove Off Campus - Grilling with TomEventVouchers112512500012506/24/2021 18:00:00 -07:00Test1Test1Test1Test1Test1Test1Test1Hot Stove Society Class VoucherTest1Test1Test1
51207748Test105/29/2021 22:14:25 -07:00########22:14:25.7789511Test1250000002500250VisaHot Stove Off Campus - Grilling with TomEventVouchers112512500012506/24/2021 18:00:00 -07:00Test1Test1Test1Test1Test1Test1Test1Hot Stove Society Class VoucherTest1Test1Test1
61207719Test205/29/2021 18:15:35 -07:00########18:15:35.7274103Test2170000001700170DiscoverHot Stove Off Campus - Southeast Asian GrillingEventVouchers185850008506/19/2021 18:00:00 -07:00Test2Test2Test2Test2Test2Test2Test2Test2Hot Stove Society Class VoucherTest2Test2Test2
71207719Test205/29/2021 18:15:35 -07:00########18:15:35.7274103Test2170000001700170DiscoverHot Stove Off Campus - Southeast Asian GrillingEventVouchers185850008506/19/2021 18:00:00 -07:00Test2Test2Test2Test2Test2Test2Test2Test2Hot Stove Society Class VoucherTest2Test2Test2
81207653Test305/29/2021 15:44:28 -07:00########15:44:28.7669810Test3900000090855MasterCardTest3Handmade Spring Pasta Virtual ClassEventVouchers125250002506/09/2021 18:00:00 -07:00Test3Test3Test3Test3Test3Test3Test3Hot Stove Society Class VoucherTest3Test3Test3
91207653Test305/29/2021 15:44:28 -07:00########15:44:28.7669810Test3900000090855MasterCardTest3Potsticker Love Virtual ClassEventVouchers135350003506/26/2021 10:00:00 -07:00Test3Test3Test3Test3Test3Test3Test3Hot Stove Society Class VoucherTest3Test3Test3
101207653Test305/29/2021 15:44:28 -07:00########15:44:28.7669810Test3900000090855MasterCardTest3Spring Gnocchi | Virtual ClassEventVouchers130300003006/18/2021 18:00:00 -07:00Test3Test3Test3Test3Test3Test3Test3Hot Stove Society Class VoucherTest3Test3Test3
111185617Test405/01/2021 08:16:56 -07:00########08:16:56.2255588Test4135000001350135VisaCinco De Mayo Happy Hour Class + Ingredient KitEventVouchers165650006505/05/2021 16:30:00 -07:00Test4Test4Test4Test4Test4Test4Test4Hot Stove Society Class VoucherTest4Test4Test4
121185617Test405/01/2021 08:16:56 -07:00########08:16:56.2255588Test4135000001350135VisaQuick and Easy Halibut Dinner Class + Ingredient KitEventVouchers170700007005/11/2021 18:00:00 -07:00Test4Test4Test4Test4Test4Test4Test4Hot Stove Society Class VoucherTest4Test4Test4
ItemsSold_5-1-2021_to_5-3
 
Upvote 0
I suppose it would be remove duplicate values in O if columns A and D are identical.

In the case of Test 3 and 4 U would be different but I'd still want O to be removed.
 
Upvote 0
Assuming the sorting stays as is. Perhaps (untested)

VBA Code:
Sub doit() 

Dim rownum as long
Dim myorder as string
Dim mydate as string

Rownum = 2

Do until cells(rownum, 1) = "" 
myorder = cells(rownum, 1)
mydate = cells(rownum, 4)
rownum = rownum + 1
Do until cells(rownum, 1) <> myorder and cells(rownum, 4) <> mydate
Cells(rownum, 25).clearcontents
rownum = rownum + 1
Loop
Loop

End sub
 
Upvote 0
Sorry I got sidetracked on other projects but I did just try this out and got the following results

Original data before macro

ItemsSold_6-14-2021_to_6-24-2021 (1).xls
ABCDO
1Order IdReference IdDATEDate OnlyAmount Paid
2122910456EB2-W8576/24/2021 2:38:22 PM -07:006/24/2021 12:00:00 AM160
3122910456EB2-W8576/24/2021 2:38:22 PM -07:006/24/2021 12:00:00 AM160
41229093PZXV3-QFEH6/24/2021 2:15:25 PM -07:006/24/2021 12:00:00 AM80
51229083CHWJA-ZHDQ6/24/2021 2:07:01 PM -07:006/24/2021 12:00:00 AM170
61229083CHWJA-ZHDQ6/24/2021 2:07:01 PM -07:006/24/2021 12:00:00 AM170
71228631CKG5F-UUY66/24/2021 1:37:48 AM -07:006/24/2021 12:00:00 AM160
81228631CKG5F-UUY66/24/2021 1:37:48 AM -07:006/24/2021 12:00:00 AM160
91228446ZENPA-XE7E6/23/2021 3:27:07 PM -07:006/23/2021 12:00:00 AM0
1012284459TWW4-CRQU6/23/2021 3:26:40 PM -07:006/23/2021 12:00:00 AM0
111228437MQWQZ-YF5F6/23/2021 3:12:13 PM -07:006/23/2021 12:00:00 AM250
121228437MQWQZ-YF5F6/23/2021 3:12:13 PM -07:006/23/2021 12:00:00 AM250
ItemsSold_6-14-2021_to_6-


and after macro:

ItemsSold_6-14-2021_to_6-24-2021 (2).xlsx
ABCDO
1Order IdReference IdDATEDate OnlyAmount Paid
2122910456EB2-W85706/24/2021 14:38:22 -07:00########160
3122910456EB2-W85706/24/2021 14:38:22 -07:00########
41229093PZXV3-QFEH06/24/2021 14:15:25 -07:00########
51229083CHWJA-ZHDQ06/24/2021 14:07:01 -07:00########
61229083CHWJA-ZHDQ06/24/2021 14:07:01 -07:00########
71228631CKG5F-UUY606/24/2021 01:37:48 -07:00########
81228631CKG5F-UUY606/24/2021 01:37:48 -07:00########
91228446ZENPA-XE7E06/23/2021 15:27:07 -07:00########0
1012284459TWW4-CRQU06/23/2021 15:26:40 -07:00########
111228437MQWQZ-YF5F06/23/2021 15:12:13 -07:00########
121228437MQWQZ-YF5F06/23/2021 15:12:13 -07:00########
ItemsSold_6-14-2021_to_6-


I'm not entirely sure what happened to the values of 80, 170 and 250 and why those were cleared. I also did tweak the macro to "Cells(rownum, 15).clearcontents" as leaving 25 for the column cleared contents in Column Y Item Discount which didn't have any info really:

VBA Code:
Sub doit()

Dim rownum as long
Dim myorder as string
Dim mydate as string

Rownum = 2

Do until cells(rownum, 1) = ""
myorder = cells(rownum, 1)
mydate = cells(rownum, 4)
rownum = rownum + 1
Do until cells(rownum, 1) <> myorder and cells(rownum, 4) <> mydate
Cells(rownum, 15).clearcontents
rownum = rownum + 1
Loop
Loop

End sub
 
Last edited:
Upvote 0
The problem is there are unique orders, unlike your example. Probably a bit short sighted of me but in future a more thorough representation of the data would be helpful ☺

I'll follow up when back at a PC in a few days if no one else gets the solution through first.
 
Upvote 0

Forum statistics

Threads
1,214,611
Messages
6,120,510
Members
448,967
Latest member
screechyboy79

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top