Function to quickly remove all duplicates from a specified column in Excel using VBA.

Examples of where this function shines:

Assume that you have been given a list of customer data, but there are multiple records for each customer. You only need one, so need to delete the rest of the duplicate information.

Many people will use VBA to loop through all the records, deleting any that occur more than once. Unfortunately, loops take more and more time as the data increases. This code is MUCH faster than using a loop to accomplish the task.

This function keeps the first entry in the list of data, so your records order is kept intact

Macro Weakness(es):

You may not want to keep the last entry in your list of data, not the first. Currently this would require sorting your data before running this function

Versions Tested:This function has been tested with Excel 2003. It should not have any issues running from any of the Office applications from 97 or higher.VBA Code Required:
Place the following code in a standard module:

A column of index numbers is created after the last column of information in the spreadsheet. This is to preserve the original order.

The data is then sorted based on the specified column, with the secondary sort key being the original order. (This ensures that the first instance of a record will be maintained.)

A column of formulas is inserted at the end of the sheet, comparing the Target Column's data for that row against the previous row. If it does not match, it is a new record, if it does match, then the record is a duplicate.

Using the autofilter, all data that has been flagged as a duplicate is deleted.

The End Result:

All duplicates will be eliminated from the specified column.

I'm afraid that you must be logged in to comment or leave a testimonial. I wish it could be otherwise, but I'm trying to keep my site spam free for everyone's benefit. If you don't yet have an account it's completely free to sign up, and a very quick process. Simply click here to Register. Not only can you post a comment here, but it gives you full access to posts questions in our forum as well!

If you already have an account, and just haven't logged in yet, what are you waiting for? Login Now!