Skip to content
AnIntent

How to Highlight Duplicates in Google Sheets With a COUNTIF Formula

Use conditional formatting and a COUNTIF custom formula to colour every repeated value in a Google Sheets column without deleting anything.

AnIntent Editorial · · 4 min read

Person working on a laptop with a spreadsheet outdoors
Photo by Gorilla ROI Data Connector on Unsplash
In this article
  1. The formula that flags repeated values
  2. Steps to add the duplicates rule
  3. This rule highlights the first copy too
  4. Why the dollar signs matter
  5. When the highlighting looks wrong
  6. Limits and what isn't covered
Share this article

You can make Google Sheets colour every cell whose value appears more than once in a column. You need one conditional formatting rule with a COUNTIF custom formula, and nothing gets deleted. If you actually want the repeats gone, use How to Remove Duplicates in Google Sheets instead.

The formula that flags repeated values

This is the example from Google's conditional formatting help page for data in A1 to A100:

=COUNTIF($A$1:$A$100,A1)>1

COUNTIF counts how many cells in $A$1:$A$100 match the value in A1. If the count is more than 1, the value is repeated and the cell gets your chosen format.

Steps to add the duplicates rule

These are the steps from Google's help page for the computer version of Sheets:

  1. Open your spreadsheet in Google Sheets on your computer.
  2. Select the range you want to check, for example A1 to A100.
  3. Click Format, then Conditional formatting. A toolbar opens on the right.
  4. Under the Format cells if drop-down, click Custom formula is. If a rule already exists, click it, or click Add new rule and then Custom formula is.
  5. Click Value or formula and enter =COUNTIF($A$1:$A$100,A1)>1.
  6. Under Formatting style, pick a fill or text colour.
  7. Click Done.

Write the formula for the first row of your selection. Google's page says to write the rule for the first row, and Sheets applies it down the rest of the range.

This rule highlights the first copy too

Google's example marks every occurrence of a repeated value, including the first one. That follows from how COUNTIF works: the count includes the cell itself. If "Smith" appears twice, both cells count 2, so both are coloured.

That is usually what you want when you are hunting for duplicates without deleting them. This article covers only highlighting every occurrence.

Why the dollar signs matter

Google's page notes that you often need dollar signs in front of column letters and row numbers so the rule uses absolute references instead of relative ones. In the duplicates formula the two parts behave differently:

  • $A$1:$A$100 is locked. Every cell is checked against the same full range.
  • A1 has no dollar signs, so it is relative. It becomes A2 for the second row, A3 for the third, and so on.

This is the most common reason the rule misbehaves. If you leave out the dollar signs on the range, it shifts along with each row, so later cells are counted against a different slice of the column and the highlighting looks random. If you lock A1 as $A$1, every cell is compared with the first cell's value. Keep the range locked and the single cell relative.

For a different column, change the letters to match. For data in C2 to C500, for example, select that range and use $C$2:$C$500 as the range and C2 as the cell.

When the highlighting looks wrong

Another rule wins. Google's page says rules are evaluated in the order listed, and the first rule found true sets the cell's format. If an older rule covers the same cells, drag the duplicates rule above it in the Conditional formatting toolbar.

Colours turn up where you didn't add a rule. Copying and pasting from a cell or range that has formatting rules also applies those rules to the pasted data, per Google. Open Format > Conditional formatting on the affected cells to see which rules came along.

Wildcards don't match. According to Google, the ?, * and ~ wildcards work only with the "Text contains" and "Text does not contain" conditions, not in custom formulas.

You want to remove the rule. In the Conditional formatting toolbar, point to the rule and click Remove.

Limits and what isn't covered

These steps follow the computer version of the page. Google publishes a separate Android version, and the menus may differ in the mobile apps.

Google's page says custom formulas can only reference the same sheet. This article doesn't cover rules that check data on another sheet.

Common questions

Does this delete the duplicate values?

No. Conditional formatting only changes how cells look. Your data stays as it is.

Why is the first occurrence highlighted too?

COUNTIF counts the cell itself, so every copy of a repeated value has a count above 1 and gets coloured.

Can the rule check for duplicates on a different sheet?

Not with a direct reference. Google's help page says custom formulas can only reference the same sheet, and this article doesn't cover cross-sheet rules.

Why are cells highlighted that I never set a rule on?

Copying and pasting from cells with formatting rules also copies those rules to the pasted data. Check Format > Conditional formatting on those cells.

Can I use wildcards like * in the custom formula?

No. Google says wildcards work only with the Text contains and Text does not contain conditions, not in custom formulas.

Hands typing on a laptop displaying a data spreadsheet
How-to

How to Use XLOOKUP in Google Sheets: Look Left, Fix #N/A, Find the Last Match

Write XLOOKUP formulas in Google Sheets that look left, replace #N/A with your own text, and find the last match.

· 3 min

More in Cloud & Productivity Software