Delete one row if data in two cells match

jski21

Board Regular
Joined
Jan 2, 2019
Messages
133
Office Version
  1. 2016
Platform
  1. Windows
Good day Mr. Excel team,

Working through a rather large dataset and could alleviate some pain but need this groups assistance. The dataset represents transportation activity. One row for pickup, one row for return. I'd like to maintain the existing dataset for reference. If I could winnow done the data by eliminating one row of a matched set that would make the analysis much more manageable. Example:

STC Data.xlsx
ABC
1Record#Client NamePickup Date
21Customer 11/2/2017
32Customer 11/2/2017
43Customer 21/2/2017
54Customer 21/2/2017
65Customer 31/3/2017
76Customer 31/3/2017
STC 2017-2022


If the Client Name in Column B and the Pickup Date in Column C on Row 1 and Row 2 are the same (this is a round trip), Row 2 would be deleted. On to Record #3. Same exercise. On to Record #5, etc. The dataset is fairly large (out to Column BJ) and lengthy (Row 578285).

I could simply run the analysis and divide by two; however, some of these are one-ways and I need to be on target with the analysis. VBA seems to be the best direction, but need a bit of direction or other ideas.

Thanks in advance for the review and counsel.

Best regards,

jski
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Does this work for you. I am not sure on the speed with 500,000 rows... Make sure to test on a backup copy of your data.

VBA Code:
Sub RemDupes()
    Cells.RemoveDuplicates Columns:=Array(2, 3), Header:=xlYes
End Sub
 
Upvote 0
Hmmm...no. I'm getting a 1004; Application-defined or object-defined error.
 
Upvote 0
ehhhhhhh....... worked for me on a few less rows... Perhaps RemoveDuplicates is not included with Excel 2016.

Nonetheless, I was happy to try and help.
 
Upvote 0
Np. Appreciate the time and consideration igold. Thanks.
 
Upvote 0
Good day gents,

I think I figured this out with the following code:

---------------------------------------------------------------------------------------------------
Sub RemDupes()

'Declared variables
Dim dataRange As Range


'Change Range cells as necessary to cover entire dataRange
Set dataRange = Range("A1:BJ578285")

'Change array numbers to the columns in which you are looking for duplicates
dataRange.RemoveDuplicates Columns:=Array(2, 3), Header:=xlYes

End Sub
---------------------------------------------------------------------------------------------------


I mentioned previously that my dataset was related to transportation (round trips) so there would be dupes. The dataset was 578,285 rows. After running the code, that was reduced to 298,651 which is a little over half if dividing the dataset by 2. So there are about 9,500 one-way trips in the dataset over a 6-year period which seems ok from a reasonable ness standpoint. I'll take it.

BTW, my Excel version is 2016.


Posting the code here for future users who may come across the same headache/need as I did.

Regards,

jski
 
Upvote 0
Solution

Forum statistics

Threads
1,215,006
Messages
6,122,666
Members
449,091
Latest member
peppernaut

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