Lesson 21 of 92 · Free Excel Course
Excel
Excel Highlight Duplicates: Find, Flag and Remove Duplicate Values
Highlight duplicates in Excel with one rule, flag repeats with COUNTIF and COUNTIFS, then remove them safely or list unique values with UNIQUE. Practice file.
Duplicates sneak into every list: a customer who signed up twice, an order pasted in two times, a name typed once with a capital and once without. Before you count, total or email anyone, you need to know where the repeats are. This lesson shows four ways to deal with them, from safest to most drastic: highlight them so you can see them, flag them with a formula, list unique values with the UNIQUE function, and remove them for good with Remove Duplicates. All the examples use one small list, so you can follow along in the practice workbook.
Highlight duplicates with one rule
Here's the list used all through this lesson: ten sign-ups with a name and a city. Some people appear more than once.
| A | B | |
|---|---|---|
| 1 | Name | City |
| 2 | Ann | Austin |
| 3 | Ben | Boston |
| 4 | Carla | Denver |
| 5 | Ann | Austin |
| 6 | Dev | Boston |
| 7 | Ben | Chicago |
| 8 | Ella | Denver |
| 9 | Carla | Denver |
| 10 | Femi | Austin |
| 11 | Ann | Austin |
To shade every repeated name:
- Select the cells to check, here A2:A11. Leave out the heading.
- On the Home tab, click Conditional Formatting.
- Point to Highlight Cells Rules, then click Duplicate Values.
- The first box already says Duplicate. In the box next to values with, keep Light Red Fill with Dark Red Text or pick another style.
- Click OK.
| A | B | |
|---|---|---|
| 1 | Name | City |
| 2 | Ann | Austin |
| 3 | Ben | Boston |
| 4 | Carla | Denver |
| 5 | Ann | Austin |
| 6 | Dev | Boston |
| 7 | Ben | Chicago |
| 8 | Ella | Denver |
| 9 | Carla | Denver |
| 10 | Femi | Austin |
| 11 | Ann | Austin |
Notice two things. First, every copy is shaded, including the first Ann in row 2. Second, the rule only looks at the cells you selected, so Ben is red even though his two rows have different cities. It's checking names, not whole rows. Switch the first box from Duplicate to Unique if you'd rather shade the one-offs instead.
The same menu path works in Excel for Mac and Excel for the web. The rule is live: type a new "Dev" in row 12 inside the range and both Devs turn red. To take the colours off, select the cells and choose Home > Conditional Formatting > Clear Rules > Clear Rules from Selected Cells. Highlighting never changes or deletes your data, which makes it the safe first step. Colour rules get a full lesson of their own in Conditional formatting.
Flag duplicates with a COUNTIF formula
A colour is easy to see but hard to filter, count or sort by. A formula gives you a TRUE or FALSE you can work with. In C2, type:
=COUNTIF($A$2:$A$11,A2)>1
COUNTIF counts how many times the name in A2 appears in the whole list. If that's more than 1, the result is TRUE. The $ signs lock the list in place so it doesn't slide down when you fill the formula to C11, while A2 changes to A3, A4 and so on. (That's the idea from absolute and relative references.) If you're new to COUNTIF, see COUNTIF, SUMIF and AVERAGEIF.
Flag only the second and later copies
Usually you want to keep the first copy and deal with the rest. Change the formula so the range grows as it goes down:
=COUNTIF($A$2:A2,A2)>1
Only the start of the range is locked. In row 5 the range is A2:A5, so it counts the Anns so far: two, so TRUE. In row 2 it's just A2, so the first Ann gets FALSE.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Name | City | Duplicate? | Repeat copy? |
| 2 | Ann | Austin | TRUE | FALSE |
| 3 | Ben | Boston | TRUE | FALSE |
| 4 | Carla | Denver | TRUE | FALSE |
| 5 | Ann | Austin | TRUE | TRUE |
| 6 | Dev | Boston | FALSE | FALSE |
| 7 | Ben | Chicago | TRUE | TRUE |
| 8 | Ella | Denver | FALSE | FALSE |
| 9 | Carla | Denver | TRUE | TRUE |
| 10 | Femi | Austin | FALSE | FALSE |
| 11 | Ann | Austin | TRUE | TRUE |
You can use the same formula as a highlight. Select A2:A11, click Home > Conditional Formatting > New Rule, choose Use a formula to determine which cells to format, type =COUNTIF($A$2:A2,A2)>1, pick a fill with Format, and click OK. Now only the repeats are coloured and each first copy stays plain. Write the formula for the top cell of your selection; Excel adjusts it for the others.
Find duplicate rows across two columns
Ben appears twice, but one Ben lives in Boston and the other in Chicago. They may be two different people. To find rows where both the name and the city match, use COUNTIFS, which checks several columns at once. In E2, type and fill down:
=COUNTIFS($A$2:$A$11,A2,$B$2:$B$11,B2)
| A | B | C | |
|---|---|---|---|
| 1 | Name | City | Row count |
| 2 | Ann | Austin | 3 |
| 3 | Ben | Boston | 1 |
| 4 | Carla | Denver | 2 |
| 5 | Ann | Austin | 3 |
| 6 | Dev | Boston | 1 |
| 7 | Ben | Chicago | 1 |
| 8 | Ella | Denver | 1 |
| 9 | Carla | Denver | 2 |
| 10 | Femi | Austin | 1 |
| 11 | Ann | Austin | 3 |
Anything above 1 is a full duplicate row. To shade whole rows like this, select A2:B11 and add a formula rule (as above) with =COUNTIFS($A$2:$A$11,$A2,$B$2:$B$11,$B2)>1; the $ before each column letter keeps every cell in the row looking at columns A and B. Add more pairs of range and cell for more columns, such as an email column. Then filter the helper column for values above 1 (see Sort and filter) to review them all together.
Remove duplicates for good
When you're sure, Excel can delete the extra rows in one go. This deletes data. Microsoft's own advice is to copy the original to another sheet first, and that's a good habit. Right-click the sheet tab, choose Move or Copy, tick Create a copy and click OK.
- Click any cell in your list (or select the exact range).
- On the Data tab, in the Data Tools group, click Remove Duplicates.
- Leave My data has headers ticked so row 1 isn't treated as data.
- Under Columns, tick the columns that must match for two rows to count as duplicates. Tick Name and City to remove only true repeat rows.
- Click OK. Excel tells you how many duplicates it removed and how many unique values remain.
Which columns you tick changes the answer a lot:
| Columns ticked | Rows removed | What's left |
|---|---|---|
| Name and City | 3 (two extra Ann/Austin rows, one extra Carla/Denver) | 7 rows, both Bens kept |
| Name only | 4 (two extra Anns, one Ben, one Carla) | 6 rows, Ben in Chicago is gone |
Excel always keeps the first row for each value and deletes the later ones. It removes the whole row, even the columns you didn't tick. So with only Name ticked, Ben in Chicago vanishes along with his city. If you change your mind, press Ctrl+Z straight away.
On a Mac, it's the same: Data tab, Remove Duplicates, tick the columns, then click the dialog's Remove Duplicates button. In Excel for the web, click Data > Remove Duplicates, clear any columns you don't want to compare, and click OK. Remove Duplicates won't run on data that has outlines or subtotals, so remove those first.
List unique values with UNIQUE (nothing deleted)
If you just need a clean list, say for a report or a drop-down list, the UNIQUE function is safer. It copies each value once into a new spot and leaves the original alone.
=UNIQUE(array, [by_col], [exactly_once])
| G | H | I | J | K | L | |
|---|---|---|---|---|---|---|
| 1 | Unique names | Unique rows | Appear once | |||
| 2 | Ann | Ann | Austin | Dev | ||
| 3 | Ben | Ben | Boston | Ella | ||
| 4 | Carla | Carla | Denver | Femi | ||
| 5 | Dev | Dev | Boston | |||
| 6 | Ella | Ben | Chicago | |||
| 7 | Femi | Ella | Denver | |||
| 8 | Femi | Austin |
=UNIQUE(A2:A11)lists the six names once each.=UNIQUE(A2:B11)compares whole rows, giving the same seven rows as Remove Duplicates with both columns ticked.=UNIQUE(A2:A11,FALSE,TRUE)sets exactly_once to TRUE, so you get only the names that were never repeated: Dev, Ella and Femi.- Wrap it in SORT for alphabetical order:
=SORT(UNIQUE(A2:A11)).
The results spill down into empty cells and update when the list changes. UNIQUE works in Microsoft 365 (Windows and Mac), Excel 2021, Excel 2024 and Excel for the web. Excel 2019 and earlier don't have it; use Advanced Filter instead.
Advanced Filter, briefly. Click a cell in the list, go to Data > Advanced (in the Sort & Filter group), choose Copy to another location, type a target cell in Copy to, tick Unique records only, and click OK. You get a one-time copy of the unique rows. It doesn't update by itself, but it works in every desktop version, including Mac.
Try it yourself
Download the practice workbook and open the Practice sheet. Yellow cells are where you type.
- Select A2:A11 and apply Duplicate Values. You should see seven red cells.
- In C2, type
=COUNTIF($A$2:$A$11,A2)>1and fill down to C11. - In D2, type
=COUNTIF($A$2:A2,A2)>1and fill down. Rows 5, 7, 9 and 11 should say TRUE. - In E2, type
=COUNTIFS($A$2:$A$11,A2,$B$2:$B$11,B2)and fill down. - In G2, I2 and L2, type the three UNIQUE formulas from the section above.
- Make a copy of the sheet, then run Remove Duplicates on A1:B11 with Name and City ticked (untick the formula columns). Check against the Removed sheet.
- On a fresh copy, tick only Name and see what happens to Ben in Chicago.
The Answers sheet has every formula working and the red cells the rule should produce.
Common mistakes
- Removing before checking. Remove Duplicates deletes rows. Highlight or flag first, then copy the sheet before you remove anything.
- Ticking too few columns. With only one column ticked, rows that share a name but differ elsewhere get deleted. Tick every column that defines a true duplicate.
- Trailing spaces. "Ann" and "Ann " (with a space) look the same but aren't duplicates to Excel, so they won't be highlighted or removed. Clean them with
=TRIM(A2)in a helper column, paste the results back as values, then check again. Text functions covers TRIM. - Expecting case to matter. COUNTIF ignores case, and so do the highlight rule and Remove Duplicates in practice: "ANN" and "ann" count as the same. That's usually what you want, but it means you can't use these tools to separate them.
- Numbers stored as text. An ID typed as text (left-aligned, often with a small green triangle) can look like a real number yet fail to match it. Select the cells, click the warning icon and choose Convert to Number before you look for duplicates.
- Formatting differences. Microsoft notes that duplicates are judged by what appears in the cell. The same date shown in two different formats counts as two unique values, so give the column one format first.
- Unlocked ranges.
=COUNTIF(A2:A11,A2)>1without the$signs shifts as you fill it down and misses rows. Lock the range with$A$2:$A$11.
What's next
You can now spot repeats, keep the first copy, and clean a list safely. The best fix is stopping bad entries before they're typed, and that's the next lesson: Drop-down lists and data validation, which includes a rule that blocks duplicates as they're typed. Missed the last one? Go back to Sort and filter, or see the full Excel course. The UNIQUE function page has more ways to use UNIQUE on its own.
Frequently asked questions
How do I highlight duplicates in Excel?
Select the cells, then go to Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values, pick a colour and click OK. Every value that appears more than once is shaded, including the first copy. It works the same way on a Mac and in Excel for the web.
How do I highlight duplicates but not the first one?
Use a formula rule instead of the built-in one. Select A2:A20, choose Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format, and enter =COUNTIF($A$2:A2,A2)>1. Only the second and later copies are shaded.
Which copy does Remove Duplicates keep?
The first one. Excel keeps the first row it finds for each value and deletes the later matching rows. The deletion is permanent once you save, so copy your data to another sheet before you start.
How do I find duplicate rows across two or more columns?
Add a helper column with COUNTIFS, for example =COUNTIFS($A$2:$A$20,A2,$B$2:$B$20,B2). A result above 1 means the whole combination (say, the same name and city) appears more than once. In Remove Duplicates, tick both columns to get the same result.
Is Remove Duplicates case-sensitive?
No. Excel treats ANN, Ann and ann as the same value, and COUNTIF ignores case too. But a stray space does count: Ann and Ann followed by a space are different, so clean the data with TRIM first.
How do I remove duplicates without deleting anything?
Use =UNIQUE(A2:A20) in an empty cell. It lists each value once and leaves your original data alone, and it updates when the data changes. UNIQUE needs Microsoft 365, Excel 2021, Excel 2024 or Excel for the web.