Excel course · Lesson 27 of 34

Removing duplicates and cleaning data

Find, flag and remove duplicate records safely, fill blanks, fix inconsistent entries with Find & Replace, and follow a repeatable data-cleaning checklist.

Advanced 16 min read

Duplicates and inconsistencies quietly ruin analysis. A customer listed twice doubles their sales in a PivotTable; Leeds, leeds and Leeds become three cities; blank cells in a category column drop rows out of every SUMIFS. This lesson shows how to detect duplicates before deleting anything, how to remove them safely, and a checklist of cleaning steps that makes any imported list trustworthy.

Step zero: work on a copy

Remove Duplicates and Find & Replace change data in place. Before cleaning, duplicate the sheet (right-click the tab › Move or Copy › tick Create a copy) or keep the raw import untouched and clean a copy. If the source arrives regularly, do the cleaning in Power Query instead, where the raw file is never modified (Power Query basics: import, clean, append, merge, refresh).

Finding duplicates first

ABCD
1CustIDNameEmailCity
2C-01Alpha Ltd[email protected]Leeds
3C-02Beta GmbH[email protected]Munich
4C-03Alpha Ltd[email protected]Leeds
5C-04Gamma SA[email protected]Lyon
6C-05Beta GmbH[email protected] Munich
7C-06Delta Inc[email protected]Boston

A customer list. C-03 duplicates C-01 exactly. C-05 looks like C-02 but its email differs in capitals and has a trailing space.

Highlight them

  1. Select the Email column, C2:C7.
  2. Choose Home › Conditional Formatting › Highlight Cells Rules › Duplicate Values.
  3. Keep Duplicate and a colour, and click OK.
  4. Only [email protected] (twice) is highlighted. [email protected] is not recognised as a duplicate of [email protected] because of the trailing space. (Capitals alone would not matter: Excel's duplicate checks ignore case.)

Count them with a formula

D6fx=SUMPRODUCT(--(TRIM($C$2:$C$7)=TRIM(C6)))

D2 =SUMPRODUCT(--(TRIM($C$2:$C$7)=TRIM(C2))), filled down. TRIM is applied to both sides, and the = comparison ignores case.

Result: 2

A plain =COUNTIF($C$2:$C$7, C2) would be enough for clean data, but here it would miss the Beta pair, because the stray space makes the two texts different. A count above 1 marks a duplicate. Filter the helper column for values greater than 1 to review them. To mark only the second and later occurrences, use an expanding range: =COUNTIF($C$2:C2, C2)>1 returns TRUE from the second appearance onward, so you can delete those rows and keep the first.

Tip. Decide what makes two rows 'the same' before you start. Same email? Same name and city? Same customer ID? The answer determines which columns you tick in Remove Duplicates.

Clean, then remove

Because Excel only recognises identical text (case aside), clean the key columns first:

  1. Add a helper column Email clean with =LOWER(TRIM(C2)) and fill down.
  2. Copy the helper column and Paste Special › Values over itself, so it no longer depends on the original.
  3. Now [email protected] appears twice, as it should.

Remove Duplicates

  1. Click inside the list.
  2. Choose Data › Data Tools › Remove Duplicates (in a table also Table Design › Tools › Remove Duplicates).
  3. Tick My data has headers.
  4. Click Unselect All, then tick only the column(s) that define a duplicate, here Email clean.
  5. Click OK. Excel reports '2 duplicate values found and removed; 4 unique values remain'.

Remove Duplicates keeps the first occurrence of each value and deletes the later ones, entire rows within the selected range. If the row you want to keep is not the first (for example the most recent record), sort the list first so the preferred row comes on top: sort by date descending, then remove duplicates.

Watch out. If you tick every column, only rows identical in all columns are removed. If you tick too few, different records that happen to share a value (two customers called 'John Smith') are merged. Review the helper-count column before pressing OK, and keep the copy you made.

Unique lists without deleting

  • Formula (Microsoft 365, 2021): =UNIQUE(C2:C7) returns each value once and updates automatically; =SORT(UNIQUE(LOWER(TRIM(C2:C7)))) cleans and de-duplicates in one formula (Dynamic arrays: spill, FILTER, SORT, UNIQUE, SEQUENCE and #).
  • Advanced Filter: Data › Sort & Filter › Advanced, tick Unique records only and Copy to another location (all versions).
  • PivotTable: put the field in Rows; each value appears once.
  • Power Query: select columns and choose Home › Remove Rows › Remove Duplicates. Note that Power Query is case-sensitive, so lowercase first.

Filling blank cells

Reports exported from other systems often show a category only on its first row and leave the rows below blank. For sorting and PivotTables every row needs its value.

  1. Select the column, for example A2:A200.
  2. Choose Home › Find & Select › Go To Special › Blanks and click OK. Only the empty cells are selected; the active cell is the first blank, say A3.
  3. Type = and press the Up Arrow key, so the formula reads =A2.
  4. Press Ctrl+Enter (Mac: Ctrl+Return). Every blank is filled with a reference to the cell above.
  5. Select the column again, copy, and Paste Special › Values to turn the formulas into fixed text.

Find & Replace for inconsistent entries

Ctrl+H (Mac: Ctrl+H or Edit › Find › Replace) opens Find and Replace. Click Options for more control:

  • Match entire cell contents prevents replacing North inside North East.
  • Match case distinguishes Ltd from LTD.
  • Within: Workbook applies the change to every sheet.
  • Wildcards: * matches any characters, ? one character; ~* finds a real asterisk.
  • Find All lists every match so you can check before replacing.
  • Replace a line break by typing Ctrl+J in the Find box (Windows).

A data-cleaning checklist

CheckHow
Extra spacesTRIM in a helper column; check LEN
Inconsistent caseUPPER / LOWER / PROPER
Numbers stored as textConvert to Number, Text to Columns, VALUE
Dates stored as textText to Columns › Date, DATEVALUE, Power Query locale
Spelling variantsSort or filter the column to see variants; Find & Replace
Blanks in key columnsGo To Special › Blanks; fill or investigate
DuplicatesCOUNTIF flags, then Remove Duplicates
Outliers and typos in numbersSort ascending/descending; MIN, MAX; conditional formatting
Future entriesData validation drop-downs (Data validation: drop-down lists and dependent lists)

Text-specific functions are covered in Text cleanup: TRIM, CLEAN, TEXTSPLIT, Flash Fill and Text to Columns. Prevention is cheaper than cure: once a list is clean, add data validation so it stays that way.

Check yourself

1. Which occurrence does Remove Duplicates keep?

2. Why does [email protected] not match [email protected] in Remove Duplicates?

3. Which formula flags the second and later occurrences of a value?

4. After Go To Special › Blanks, how do you fill each blank with the value above?

5. Which tool removes duplicates while keeping the original data untouched and repeatable?

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 12 KB