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.
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
| A | B | C | D | |
|---|---|---|---|---|
| 1 | CustID | Name | City | |
| 2 | C-01 | Alpha Ltd | info@alpha.com | Leeds |
| 3 | C-02 | Beta GmbH | sales@beta.de | Munich |
| 4 | C-03 | Alpha Ltd | info@alpha.com | Leeds |
| 5 | C-04 | Gamma SA | contact@gamma.fr | Lyon |
| 6 | C-05 | Beta GmbH | Sales@Beta.de | Munich |
| 7 | C-06 | Delta Inc | hello@delta.com | 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
- Select the Email column,
C2:C7. - Choose Home › Conditional Formatting › Highlight Cells Rules › Duplicate Values.
- Keep Duplicate and a colour, and click OK.
- Only
info@alpha.com(twice) is highlighted.Sales@Beta.deis not recognised as a duplicate ofsales@beta.debecause of the trailing space. (Capitals alone would not matter: Excel's duplicate checks ignore case.)
Count them with a formula
| C | D | |
|---|---|---|
| 1 | Count | |
| 2 | info@alpha.com | 2 |
| 3 | sales@beta.de | 2 |
| 4 | info@alpha.com | 2 |
| 5 | contact@gamma.fr | 1 |
| 6 | Sales@Beta.de | 2 |
| 7 | hello@delta.com | 1 |
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.
Clean, then remove
Because Excel only recognises identical text (case aside), clean the key columns first:
- Add a helper column
Email cleanwith=LOWER(TRIM(C2))and fill down. - Copy the helper column and Paste Special › Values over itself, so it no longer depends on the original.
- Now
sales@beta.deappears twice, as it should.
Remove Duplicates
- Click inside the list.
- Choose Data › Data Tools › Remove Duplicates (in a table also Table Design › Tools › Remove Duplicates).
- Tick My data has headers.
- Click Unselect All, then tick only the column(s) that define a duplicate, here
Email clean. - 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.
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.
- Select the column, for example
A2:A200. - 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. - Type
=and press the Up Arrow key, so the formula reads=A2. - Press
Ctrl+Enter(Mac:Ctrl+Return). Every blank is filled with a reference to the cell above. - 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
NorthinsideNorth East. - Match case distinguishes
LtdfromLTD. - 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+Jin the Find box (Windows).
A data-cleaning checklist
| Check | How |
|---|---|
| Extra spaces | TRIM in a helper column; check LEN |
| Inconsistent case | UPPER / LOWER / PROPER |
| Numbers stored as text | Convert to Number, Text to Columns, VALUE |
| Dates stored as text | Text to Columns › Date, DATEVALUE, Power Query locale |
| Spelling variants | Sort or filter the column to see variants; Find & Replace |
| Blanks in key columns | Go To Special › Blanks; fill or investigate |
| Duplicates | COUNTIF flags, then Remove Duplicates |
| Outliers and typos in numbers | Sort ascending/descending; MIN, MAX; conditional formatting |
| Future entries | Data 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?
Later duplicates are deleted, so sort first if you prefer a particular row.
2. Why does Sales@Beta.de not match sales@beta.de in Remove Duplicates?
Excel's duplicate check ignores case but not spaces.
3. Which formula flags the second and later occurrences of a value?
The expanding range counts only occurrences up to the current row.
4. After Go To Special › Blanks, how do you fill each blank with the value above?
Ctrl+Enter enters the relative formula =cell above into every selected blank.
5. Which tool removes duplicates while keeping the original data untouched and repeatable?
Power Query works on a copy of the source and repeats the steps on refresh.