Excel guide · 5 min read
How to count duplicates in Excel
=COUNTIF($B$2:$B$11,B2) next to each row. For one total, decide which number you mean: entries that have a duplicate, =SUMPRODUCT(--(COUNTIF(B2:B11,B2:B11)>1)); extra copies that Remove Duplicates would delete, =ROWS(B2:B11)-ROWS(UNIQUE(B2:B11)); or duplicate rows across all columns, =ROWS(A2:D11)-ROWS(UNIQUE(A2:D11)).Sample data
Every result on this page was calculated from this sheet by the same spreadsheet engine the Cellwise app uses.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Order | Product | Qty | |
| 2 | 50211 | [email protected] | Desk lamp | 2 |
| 3 | 50212 | [email protected] | Monitor arm | 1 |
| 4 | 50211 | [email protected] | Desk lamp | 2 |
| 5 | 50215 | [email protected] | Cable tray | 4 |
| 6 | 50216 | [email protected] | Desk lamp | 1 |
| 7 | 50215 | [email protected] | Cable tray | 4 |
| 8 | 50219 | [email protected] | Footrest | 1 |
| 9 | 50220 | [email protected] | Monitor arm | 2 |
| 10 | 50224 | [email protected] | Footrest | 1 |
| 11 | 50226 | [email protected] | Cable tray | 3 |
Download this sheet as an Excel practice file (.xlsx)
Decide which "count of duplicates" you need
"How many duplicates are there?" has at least three right answers, and people often compare two of them and think one formula is broken. In the order export above, j.okafor appears 3 times, sam.li twice and m.lopez twice.
Entries that are duplicated counts every copy, including the first: 3 + 2 + 2 = 7. Extra copies counts only the repeats, which is what you would delete to clean the list: 2 + 1 + 1 = 4. Duplicated values counts the values that repeat at all: 3. Pick the one that answers your real question: "how many rows are affected" is the first, "how many will Remove Duplicates delete" is the second, and "how many customers ordered more than once" is the third.
How many times each value repeats
Put =COUNTIF($B$2:$B$11,B2) in a helper column and fill it down. The dollar signs keep the range fixed while B2 moves with each row. Any number above 1 is a duplicate, and the number tells you how many copies exist. Sort or filter the column, largest first, to see the worst offenders.
For a summary instead of a column, list each value once with its count. In Excel 365, HSTACK puts the unique emails next to their counts in one spill, and the count updates when new orders are added.
Result: spills 6 rows × 2 columns
| [email protected] | 3 |
| [email protected] | 2 |
| [email protected] | 2 |
| [email protected] | 1 |
| [email protected] | 1 |
| [email protected] | 1 |
Six emails with their counts: j.okafor 3, sam.li 2, m.lopez 2, r.gupta 1, t.berg 1, and "[email protected] " (with a trailing space) 1.
Total entries that are duplicates
COUNTIF with the whole range as the criteria returns a count for every row at once. Comparing that with >1 gives TRUE for each duplicated entry, the double minus turns TRUE and FALSE into 1 and 0, and SUMPRODUCT adds them up. It works in every version of Excel without Ctrl+Shift+Enter.
This is the number of rows that a Duplicate Values conditional format would colour, so use it when you want to check that highlight or report how much of a list is affected.
Result: 7
7: three j.okafor rows, two sam.li rows and two m.lopez rows (one typed as M.Lopez).
Extra copies, and how many values are duplicated
The number of extra copies is the number of entries minus the number of distinct values. ROWS counts the entries and ROWS(UNIQUE()) counts the distinct ones. This is the figure Data > Remove Duplicates reports when it says "4 duplicate values found and removed", so use it to know in advance what a clean-up will delete. In Excel 2019 or older, use =ROWS(B2:B11)-SUMPRODUCT(1/COUNTIF(B2:B11,B2:B11)), which needs a range with no blank cells.
To count how many values repeat at all, divide each duplicate flag by its own count, so each repeated value adds up to exactly 1: =SUMPRODUCT((COUNTIF(B2:B11,B2:B11)>1)/COUNTIF(B2:B11,B2:B11)). For this list it returns 3, meaning three customers ordered more than once.
Result: 4
4 extra copies: 10 entries, 6 distinct emails. The trailing-space r.gupta is still counted as a different email (see below).
Duplicate rows across several columns
A duplicate row means every column matches, not just the email. Order 50211 was imported twice with the same email, product and quantity, and so was 50215. j.okafor's order 50224 is a different order, so it is not a duplicate row.
In Excel 365, UNIQUE on a multi-column range compares whole rows, so the same subtraction counts duplicate rows. In older versions, add a helper column with =COUNTIFS($A$2:$A$11,A2,$B$2:$B$11,B2,$C$2:$C$11,C2,$D$2:$D$11,D2) and count the values above 1; that gives the rows involved (4 here) rather than the extra copies (2).
Result: 2
2 duplicate rows: the second copy of order 50211 and the second copy of order 50215.
Why your count is off: case, spaces and numbers as text
COUNTIF, UNIQUE and Remove Duplicates all ignore upper and lower case, so M.Lopez and m.lopez count as the same email. That is usually what you want for emails. For a case-sensitive count of one value, use =SUMPRODUCT(--EXACT(B2:B11,B7)), which counts only exact matches: 1 here.
Spaces are not ignored. "[email protected] " with a trailing space is a different value to every one of these tools, so a real duplicate goes uncounted. Clean the text before counting: UNIQUE accepts a calculated range, so =ROWS(B2:B11)-ROWS(UNIQUE(TRIM(B2:B11))) counts 5 extra copies. For a lasting fix, trim the column itself.
Two more traps: COUNTIF treats * and ? in a value as wildcards, so a code like AB*1 also counts AB-X1. And COUNTIF counts the number 1001 and the text "1001" as a match, while UNIQUE keeps them apart, so the two methods can disagree on imported IDs.
Result: 5
5 extra copies once the trailing space is removed: r.gupta now counts as a repeat too.
Common mistakes
Comparing "entries that are duplicates" with "copies to delete"
7 and 4 are both correct for this list. The first counts every copy, the second only the repeats. Say which one you are reporting.
Counting duplicates on one column when you mean duplicate rows
A customer ordering twice is not a duplicate row. Use UNIQUE on all columns, or COUNTIFS on every column, before deleting anything.
Trusting the count on untrimmed imported data
Trailing and double spaces make duplicates look unique. Count with UNIQUE(TRIM(range)) or clean the column first.
Using SUMPRODUCT(1/COUNTIF()) on a range with blanks
A blank cell makes the division fail with #DIV/0!. In Excel 365, use the UNIQUE versions, or limit the range to the filled rows.
FAQ
How do I count the number of duplicates in a column?
For the number of entries that have a copy, use =SUMPRODUCT(--(COUNTIF(A2:A100,A2:A100)>1)). For the number of extra copies, use =ROWS(A2:A100)-ROWS(UNIQUE(A2:A100)) in Excel 365, or =ROWS(A2:A100)-SUMPRODUCT(1/COUNTIF(A2:A100,A2:A100)) in older versions.
How do I count how many times a value appears in Excel?
Use =COUNTIF($A$2:$A$100,A2) for the value in A2, or type the value: =COUNTIF(A2:A100,"[email protected]"). COUNTIF is not case-sensitive.
How do I count duplicates without counting the first occurrence?
Subtract the distinct values from the total: =ROWS(range)-ROWS(UNIQUE(range)). Per row, =COUNTIF($A$2:A2,A2)>1 marks only the second and later copies as TRUE.
Can I count duplicates without a formula?
On a copy of the data, use Data > Remove Duplicates: the message tells you how many duplicates were removed and how many unique values remain. A PivotTable with the column in Rows and again in Values (as Count) shows how often each value appears.
Is COUNTIF case-sensitive when counting duplicates?
No. COUNTIF, COUNTIFS, UNIQUE and Remove Duplicates all treat ABC and abc as the same. For a case-sensitive count, use SUMPRODUCT with EXACT.
Functions used
COUNTIFCounts cells that matchCOUNTIFSCounts with several conditionsSUMPRODUCTMultiply then addUNIQUERemoves duplicates, spillsHSTACKJoins arrays side by sideTRIMRemoves extra spacesEXACTSame text, case included?
Related guides
- How to find duplicates in Excel
- How to remove duplicates in Excel
- How to count unique values in Excel
- How to create a unique list in Excel
- How to count cells that are not blank in Excel
- How to count Yes and No answers in Excel
Updated