Excel and Google Sheets how-to
Find duplicates in a list with COUNTIF
A mailing list where some people signed up twice. One formula shows how many times each email appears, so the repeats stand out.
| A | B | C | |
|---|---|---|---|
| 1 | Count | Status | |
| 2 | ana@example.com | 2 | Duplicate |
| 3 | raj@example.com | 2 | Duplicate |
| 4 | kim@example.com | 1 | |
| 5 | ana@example.com | 2 | Duplicate |
| 6 | lee@example.com | 1 | |
| 7 | raj@example.com | 2 | Duplicate |
| 8 | sam@example.com | 1 |
Sample data. Emails in A, the count formula in B2 and the label formula in C2 are copied down.
The formula
Click the first Count cell (B2) and type:
=COUNTIF(A:A,A2)B2 shows 2: ana@example.com is in the list twice. Copy it down. Every 1 is a value that appears once, and every number above 1 is a duplicate. Here ana and raj show 2.
- A:A is the column to search.
- A2 is the value to count, the email on this row.
Label the duplicates
Wrap the count in IF to show a word instead of a number:
=IF(COUNTIF(A:A,A2)>1,"Duplicate","")Rows 2, 3, 5 and 7 show Duplicate and the rest stay blank. Filter the column on Duplicate to see them together.
Mark only the second copy
To delete repeats but keep the first copy of each, count only from the top of the list down to the current row:
=IF(COUNTIF($A$2:A2,A2)>1,"Repeat","")Only rows 5 and 7 show Repeat, the second time ana and raj appear. The range grows as you copy down ($A$2:A2, then $A$2:A3, and so on), so the first copy never counts as a repeat. Filter on Repeat, delete those rows, and one copy of each email stays.
Count unique values
How many different emails are in A2:A8?
=SUMPRODUCT(1/COUNTIF(A2:A8,A2:A8))The answer is 5. How many extra copies are there?
=ROWS(A2:A8)-SUMPRODUCT(1/COUNTIF(A2:A8,A2:A8))That gives 2. Use a range with no empty cells: a blank cell in it gives #DIV/0!. In Excel 2021 and later, Microsoft 365 and Google Sheets, =UNIQUE(A2:A8) lists each email once, here 5 rows.
Remove or highlight them with the menus
Work on a copy of the sheet first. In Excel, select the list, then Data > Remove Duplicates. To colour them instead: Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values.
In Google Sheets, select the list, then Data > Data cleanup > Remove duplicates, and choose the columns to compare. Google counts values that differ only in capitals as duplicates. To colour them: Format > Conditional formatting, pick "Custom formula is" and enter:
=COUNTIF($A$2:$A$8,A2)>1Two values look the same but are not counted
COUNTIF ignores capitals, so =COUNTIF(A2:A8,"ANA@EXAMPLE.COM") still finds 2. A space you cannot see is different: if H2 holds "kim@example.com " with a space at the end, this finds nothing:
=COUNTIF(A2:A8,H2)It shows 0. TRIM removes the extra space before counting:
=COUNTIF(A2:A8,TRIM(H2))Now it shows 1. To clean a whole column, put =TRIM(A2) in a spare column, copy it down, then paste the results back as values. COUNTIF, SUMPRODUCT and ROWS work in every version of Excel and in Google Sheets.
Templates with the math already done
Rather skip the formulas? These templates come with every formula built and checked, plus a filled-in sample.
- Wedding Guest List SpreadsheetEvery guest, household and plus-one with RSVPs, meals and seating.
- Sales Tracker and Dashboard 2027Every sale in one workbook, with revenue, top products and top customers on a dashboard.
- Recruitment Tracker SpreadsheetOpen roles and every candidate in one place, moved through your hiring pipeline.
More how-tos
- Find a price by its code with XLOOKUPType a product code, get its price back from your price list. One formula, no helper columns.
- Total each category with SUMIFSAdd up all the Fuel, all the Office, all the Meals: one formula per category, and more rules when you need them.
- Check two conditions at once with IF and ANDFree shipping only when the order is 50 or more and ships in Canada: one IF, one AND, done.
- Add leading zeros to numbersType 00021 and Excel or Google Sheets shows 21, because to them it is just the number 21. Here is how to get the zeros back, and keep them.
- Fix #DIV/0! in an averageAn average of nothing is a division by zero, so AVERAGE shows #DIV/0! until the first number arrives. One IF fixes it.
- Count rows that meet two conditions with COUNTIFSHow many of Ana's deals were 500 or more? COUNTIFS answers it in one cell, and takes as many rules as you need.
- Calculate percentage changeSales went from 400 to 500. That is a 25% increase, and one short formula works it out for every row.
- Calculate years of service from a start dateAna started on 15 March 2019. How many full years has she worked? DATEDIF counts them, and the same formula works out an age from a date of birth.
- Combine first and last name into one cellFirst names in one column, last names in the next, and you need "Ana Lopez" in one cell. The & sign joins them.
- Split a full name into first and last nameYour list has "Ana Lopez" in one cell and you need Ana and Lopez in two. Two short formulas find the space and split there.
- Free pricing calculatorsPrice a job from your real costs and margin. No sign up.






