Ron Bayes
asked on
Excel Macro to Remove Duplicates
Hello,
I have an Excel spreadsheet that has a date in column A and employee name in column I. I'd like to get a macro that will identify and delete duplicates if there is a match. For example, there are two rows on 09/01/2018 for John Doe so the first occurrence would be deleted.
Thanks
I have an Excel spreadsheet that has a date in column A and employee name in column I. I'd like to get a macro that will identify and delete duplicates if there is a match. For example, there are two rows on 09/01/2018 for John Doe so the first occurrence would be deleted.
Thanks
What version of Excel are you running? In 2010 and above (maybe earlier versions) there is a Remove Duplicates option under the Data tab. Will that not perform what is needed?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Mike Schrock - 2010 version. The spreadsheet has two years of data. Basically a headcount spreadsheet with a monthly snapshot date. So the majority of employees will show up each month but should only be 1 record/row per month. With that structure I cannot remove duplicates in the date column as there are several per employee and I cant in the name column because the employee will have multiple records as they show up each month. So I needed a macro IF statement saying if the month/date/year and employee matches another employee name within the same date range to delete the second occurrence and loop through until the end of the spreadsheet.
Did you try my macro?
Your original question says
For example, there are two rows on 09/01/2018 for John Doe so the first occurrence would be deletedwhich implies to me that a duplicate is based on a combination of name and date. Your explanation to Mike says
So I needed a macro IF statement saying if the month/date/year and employee matches another employee name within the same date range to delete the second occurrence...implies to me that you don't care about the name and want to delete duplicates based on date alone. Which is it?
ASKER
No - you read it correct the first time. Perhaps my description to Mike was not clear. I've not had a chance to test it yet but will shortly.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you!
You're welcome!
Nice solution Neeraj.
Thanks Martin!