56 free macros indexedAll toolsHow to runBlogGitHub ↗

Remove Duplicates by Multiple Columns

Delete rows where the values in two or more columns you choose are all the same

windows · mac · Excel 2016+ · Free


What it does

Excel's built-in Data → Remove Duplicates can dedupe rows, but only when every column matches. That's almost never what you want when cleaning real data. You want to dedupe by name and email while ignoring the phone number that changed between orders. This macro lets you pick exactly which columns count for the dedup check, so the messy real-world cases work.

Real-world example

Picture a finance analyst at a 4-branch retail chain doing month-end reconciliation. The chain's POS exports a CSV every night, and by the end of the month she's got a transactions sheet with 8,000 rows. The problem: when a customer pays in two installments, the POS writes two rows with the same customer email and the same order number, but a different timestamp and a different rep code on each. She wants one row per order, not two.

Her current workflow goes like this. Add a helper column, =A2&"|"&B2&"|"&C2, fill down 8,000 rows. Sort by the helper. Eyeball each duplicate to decide which row to keep. Delete the loser. Forget the helper column three days later and email her boss a sheet with a mystery column M called "concat".

That's 20 to 25 minutes of mostly clicking, and one in fifteen times she deletes the wrong row.

With this macro, she selects the data, runs the macro from Alt+F8, types 1,5 (customer email, order number), and 30 seconds later the duplicate rows are gone and the helper column never existed. The same cleanup that used to eat half her morning is now something she does between two sips of coffee.

The math: on a typical 8,000-row monthly export, expect about 24 minutes saved per cleanup. Multiply by 12 months. That's not life-changing. It's just a few hours a year you get back, and zero "wait, did I delete the right Acme row" anxiety.

How to use

First time? See How to run our tools for the 30-second setup.

  1. Paste your data into the workbook (row 1 should be your headers).
  2. Select the full data range, including the header row.
  3. Press Alt + F8 (Windows) or Option + F8 (Mac), pick RemoveDuplicatesMultiColumn, click Run.
  4. Type the column numbers you want to dedupe by, separated by commas. 1,3 means columns 1 and 3. Rows are duplicates only when all the chosen column values match an earlier row.
  5. The macro deletes the duplicate rows and shows a count.

FAQ

Which row gets kept when there's a duplicate?

The first occurrence, top to bottom. Subsequent rows with matching key columns are deleted. So if you want to keep the most recent record, sort your data by date descending before running the macro.

Is the comparison case-sensitive?

No. Acme and ACME are treated as the same value. If you genuinely care about case (rare in dedup), pre-process your text first.

What about whitespace differences?

Two cells reading Acme and Acme (trailing space) are treated as different. That's a common cause of "this should match but doesn't" mysteries. Run Trim Whitespace From All Cells first to normalize.

Will it delete the entire row or just the cells in my selection?

The entire row. That matches what most people expect when they say "remove duplicate rows." If your spreadsheet has data in columns to the right of your selection that you need to keep, copy the data to a fresh sheet first.

Can I undo it?

Yes, hit Ctrl/Cmd + Z in Excel right after running. Undo isn't 100% guaranteed across all Excel versions for VBA-driven changes, so always work on a copy of your data, not the original.

Did this tool work for you?

One click. We use this to fix tools that don't work and prioritize what to build next.

Related tools