Delete ALL duplicates - VBA

broch

New Member
Joined
Jun 12, 2011
Messages
22
Hi All,

I have a dataset (columns A:L) on worksheet called "Total". Column A contains the row number of each record, and is the only unique field. I have another dataset on a worksheet called "Payables" which is a subset of the "Total" dataset, (ie: ALL the data in "Payables" appears in "Total").

What I need to do is identify all the records which are not payable. (ie: They would appear in the "Total" data but not in the "Payables" data). So I have created a third worksheet called "Non-Payables" and I've written code that copies and pastes both datasets onto this worksheet, with the "Payables" set being directly below the "Total" set.

The last step should be simple. I now need code that will check column A of the "Non-payables worksheet" identifying duplicates and deleting BOTH the rows on which the duplicates appear, thereby leaving me with a dataset which is essentially "Total" minus "Payables"

I've found loads of sites with code that will remove the second occurrences of each duplicate, but not BOTH duplicates. Can anyone help?

At the moment, I'm achieving this by using a recorded macro that highlights duplicates in red, then filters by colour, deletes all the red rows and clears the filter. This works, but boy is it slow and clunky.

Many thanks.

Brendan
 
WOW!

Thanks GTO and Mirabeau.
The code samples you've both given are way beyond my translating ability.
But I'll give them both a try as soon as I can and report back.

Thanks a million for your help!
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Here is a non-code solution, using a query table. It is refreshable like a pivot table, though can be set to refresh automatically on file open or every n minutes. It can be made to do much more if required. It is a query on the other two worksheets - so, no populating the sheet with both other datasets & then modifying, just going directly to the result.

BTW, likely this could be run directly on your database without needing to populate Totals and Payables worksheets.

Assumes you have a worksheet name Totals and another Payables. I've assumed the common field name is "RecID". Start via menu ALT-D-D-N and follow the wizard, electing to edit in MS Query at the final step. (If you get a message about no visible tables select 'options' and then 'system tables' to see the worksheet names as data sources.) Edit the SQL to be like below.

regards

Code:
SELECT T.*
FROM {oj [Totals$] T LEFT OUTER JOIN [Payables$] P ON T.RecID = P.RecID}
WHERE P.RecID Is Null
 
Upvote 0
PS

In my previous post I assumed the data is well set up, with headers in row 1 and data immediately under. If not, modify the SQL to suit.

F
 
Upvote 0

Forum statistics

Threads
1,225,155
Messages
6,183,208
Members
453,151
Latest member
Lizamaison

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