Google Sheets recipe
How to highlight duplicates in Google Sheets
Add a conditional formatting rule with the custom formula =COUNTIF(range, first_cell)>1 and every value that appears more than once gets the color. The range stays fixed while the first cell moves down with each row. The same formula in a helper column returns TRUE or FALSE per row, a quick way to test the rule.
Steps
- Keep the values in one column, for example A2:A7, with a header in row 1.
- Select A2:A7, then open Format → Conditional formatting.
- Under the rule type, choose Custom formula is.
- Enter the formula from the first example. The COUNTIF range is locked with dollar signs, and the criterion is the first selected cell, A2.
- Choose the fill color and apply the rule. Every value whose count is above 1 gets colored, the first copy included.
- To leave the first copy alone, grow the range as in the third example: only its start is locked.
- For a match that respects uppercase and lowercase, use the EXACT version from the fourth example.
Examples
The examples use this table, starting in A1:
| ana@x.ro |
| dan@x.ro |
| ANA@x.ro |
| ion@x.ro |
| dan@x.ro |
| ana@x.ro |
=COUNTIF($A$2:$A$7, A2)>1Result: TRUE
The rule itself, written for the first cell A2. TRUE means the value appears more than once in the list.
Run in a Google Sheet (English US locale) on .
=ARRAYFORMULA(COUNTIF(A2:A7, A2:A7)>1)Result:
| TRUE |
| TRUE |
| TRUE |
| FALSE |
| TRUE |
| FALSE |
The same test for the whole column in one cell: one TRUE or FALSE per row, handy for checking before you color anything.
Run in a Google Sheet (English US locale) on .
=COUNTIF($A$2:A6, A6)>1Result: TRUE
Only the repeats. The range grows from A2 down to the current row, so the first copy counts as 1 and stays unmarked. Here it is the second dan@x.ro.
Run in a Google Sheet (English US locale) on .
=SUMPRODUCT(EXACT($A$2:$A$7, A4)*1)>1Result: FALSE
Case-sensitive version for ANA@x.ro. EXACT sees ana@x.ro and ANA@x.ro as different, so the result is FALSE.
Run in a Google Sheet (English US locale) on .
=ARRAYFORMULA(COUNTIF(A2:A7, TRIM(A2:A7))>1)Result:
| TRUE |
| TRUE |
| TRUE |
| FALSE |
| TRUE |
| TRUE |
TRIM on the criterion turns the last criterion into ana@x.ro, which the column holds twice, so the last row now shows TRUE. The range is not trimmed, and the other rows stay as in the second example.
Run in a Google Sheet (English US locale) on .
Common errors
- COUNTIF ignores case, so ana@x.ro and ANA@x.ro are flagged as duplicates. Use SUMPRODUCT with EXACT when the case matters.
- A space at the end makes a different value: "ana@x.ro " is not flagged against ana@x.ro. Clean the data with TRIM, or put TRIM around the criterion in a helper column as in the last example.
- A fixed range gives TRUE for every copy, the first one too. The growing range from the third example gives TRUE only for the later copies.
- In a RO-locale file, the rule must use ";" between arguments. The same rule typed with a comma is rejected as an invalid formula.
Compared with Excel
Same method in Excel: Conditional Formatting → New Rule → Use a formula, with the same COUNTIF rule. Excel also has a built-in Duplicate Values rule.