Skip to content
SheetFluent

How to find duplicates in Excel with COUNTIF

SheetFluent team · · 6 min read

Next to your list, type =COUNTIF($A$2:$A$8,A2)>1 and fill it down. It shows TRUE for every value that appears more than once in A2:A8, and FALSE for values that appear once. Swap in your own range, and keep the dollar signs so the range stays put as you fill.

How the formula works

COUNTIF counts the cells in a range that match a condition. =COUNTIF($A$2:$A$8,A2) reads as "count how many cells from A2 to A8 hold the same value as A2".

A value that appears once gives 1, because it only matches itself. A value that appears twice gives 2 on both of its rows. So adding >1 turns the count into a yes-or-no answer: TRUE means "this value has a twin somewhere in the list".

The range has dollar signs, $A$2:$A$8, because it must be the whole list on every row. The second part, A2, has none, so it changes to A3, A4 and so on as you fill down. Each row checks its own value against the whole list.

If you'd rather see a number than TRUE or FALSE, leave off the >1. The count tells you how many copies there are, which helps when one value appears five times and you want to find it first.

=COUNTIF($A$2:$A$8,A2)>1

See also: Lock a cell with $

Step by step

1. Click the first empty cell to the right of your data in row 2. Add a header like "Repeat?" in row 1 so you remember what the column is.

2. Type =COUNTIF( and select the whole column of values, for example A2:A8.

3. Press F4 once to add the dollar signs, giving $A$2:$A$8. On a Mac, press Cmd+T, or type the dollar signs by hand.

4. Type a comma, click A2, close the parentheses, and type >1. The full formula is =COUNTIF($A$2:$A$8,A2)>1.

5. Press Enter, then fill the formula down to the last row: double-click the small square at the bottom-right corner of the cell, or drag it.

6. Turn on a filter (Data > Filter) and show only TRUE to see every duplicate together. Sort by column A as well, so the copies sit next to each other.

Highlight duplicates instead

If you only want to see the duplicates and don't need a helper column, use conditional formatting.

In Excel, select the range, then go to Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values. Pick a color and click OK. Every value that appears more than once is shaded.

In Google Sheets there is no ready-made duplicates rule, so you use the same COUNTIF formula. Select A2:A8, go to Format > Conditional formatting, choose Custom formula is, and enter =COUNTIF($A$2:$A$8,A2)>1. The formula is written for the first cell of the range, and Sheets adjusts it for the others.

The custom formula also works in Excel (New Rule > Use a formula to determine which cells to format). That's useful when you want to shade the whole row and not just one cell: select A2:C8 and use =COUNTIF($A$2:$A$8,$A2)>1, with a dollar sign before the A so every column checks column A.

Flag only the second and later copies

=COUNTIF($A$2:$A$8,A2)>1 marks every copy, including the first. That's what you want for finding duplicates. If you plan to delete the repeats and keep one of each, you need to mark only the later copies.

Change the range so it ends at the current row: =COUNTIF($A$2:A2,A2)>1. Now each row only counts the rows above it and itself, so the first copy gives FALSE and the later ones give TRUE. Our article on removing duplicates walks through deleting them safely.

See also: How to remove duplicates in Excel

Count how many duplicates there are

Once the helper column is in place, count the TRUE results: =COUNTIF(B2:B8,TRUE) gives how many rows belong to a duplicate group.

To count rows that would be removed (every copy after the first), use the running version in the helper column and count its TRUE results in the same way.

The difference between the two counts tells you how many values are involved. In the practice list below, four rows belong to a duplicate group, but only two of them are extra copies.

Compare two columns: find values in both lists

A common job is checking one list against another: which order IDs in this week's export were already in last week's? Point COUNTIF at the other list.

If this week's IDs are in A2:A50 and last week's are in D2:D80, type =COUNTIF($D$2:$D$80,A2)>0 next to the first ID and fill down. TRUE means the ID is in both lists. Here the test is >0, not >1, because the value isn't in the range it's searching, so a single match is enough.

If the lists are on different sheets, include the sheet name in the range, for example =COUNTIF('Last week'!$A$2:$A$80,A2)>0. Quotes go around a sheet name that has a space in it.

See also: How to reference another sheet in Excel

When COUNTIF misses duplicates or finds false ones

Extra spaces. "R-1042" and "R-1042 " are different text, so they won't match. Clean the column with =TRIM(A2) in a helper column first.

Capital letters. COUNTIF ignores case, so "abc" and "ABC" count as duplicates. Usually that's what you want.

Wildcard characters. COUNTIF treats * and ? in the condition as wildcards. If your values contain those characters, matches can be wrong. Put a tilde (~) before them to make them plain characters.

Very long numbers. COUNTIF can treat long number-like codes (more than 15 digits, such as card or account numbers) as the same number, so different codes look like duplicates. For those, compare them as text with a different method, or check the matches by eye.

See also: Remove extra spaces with TRIM, Count with two conditions using COUNTIFS

Try it here

Type the formula into the answer cell, then press Enter or Check.

In B2, write a formula that shows TRUE when the order ID in A2 appears more than once in A2:A8. It will be filled down to B8.

AB
1Order IDRepeat?
2R-1042 (answer cell)
3R-1043
4R-1044
5R-1042
6R-1045
7R-1046
8R-1044
Start practicing

Questions people ask

Why does every copy show TRUE, including the first?

Because each row counts the whole list, and every copy sees the others. To mark only the later copies, end the range at the current row: =COUNTIF($A$2:A2,A2)>1.

Why do some duplicates show FALSE after filling down?

The range probably has no dollar signs, so it slides down with each row and stops counting the rows above. Lock it with $A$2:$A$8. (If every row shows the same answer, you locked the A2 part too: keep it as plain A2.)

Does this work in Google Sheets?

Yes. The COUNTIF formula is the same in Google Sheets, and you can use it as a custom formula in conditional formatting to highlight duplicates.

Can I find duplicates across two columns at once?

Yes. To match on both columns, use COUNTIFS: =COUNTIFS($A$2:$A$8,A2,$B$2:$B$8,B2)>1 is TRUE only when the same pair appears more than once.

Keep practicing

Practice this in the full lesson: Count what matches with COUNTIF