Highlight Duplicates in One Column With a Formula
How to highlight repeated IDs in one column with a COUNTIF conditional formatting rule: the fixed list, the moving cell, the steps for Excel and Google Sheets, and what to check.

To see repeated customer IDs in a column before you clean a list, use a conditional formatting rule built on COUNTIF. The formula for IDs in B2:B100 is =COUNTIF($B$2:$B$100,B2)>1, and it works the same way in Google Sheets. The Conditional Formatting Generator writes the rule and the range for you.
The COUNTIF rule
COUNTIF counts how many cells in a range equal a given value. For a list of IDs in column B, rows 2 to 100, the rule is:
=COUNTIF($B$2:$B$100,B2)>1
For each cell, the formula counts how often its value appears in the whole list. If the count is greater than 1, the value occurs more than once, and the cell is coloured. Every cell with a repeated ID is highlighted, including the first occurrence.
The count must be greater than 1, not greater than 0. A cell always finds itself in the list, so a unique value gives a count of exactly 1.

In the generator, pick the rule Duplicates in one column and enter the range B2:B100. The library formulas are built in the browser, so nothing you enter is sent anywhere.
How the fixed and moving references work
The formula has two references, and they behave differently.
$B$2:$B$100is the list. The dollar signs fix it, so every cell compares itself with the same 99 cells.B2is the tested cell. It has no dollar signs, so it moves down with the rule. In B3 the formula tests B3, in B4 it tests B4.

If you remove the dollar signs from the list, the list moves down as well. B3 would then count in B3:B101, and the rule would miss duplicates that sit above the cell. This is the usual reason a duplicate rule colours some repeated values and not others. For the same reasoning with a fixed column in a whole-row rule, see Highlight a Whole Row Based on One Cell's Value.
Microsoft documents the function on its support page COUNTIF function.
Steps in Excel and Google Sheets
In Excel:
- Select B2:B100.
- Open Home > Conditional Formatting > New Rule.
- Choose Use a formula to determine which cells to format.
- Enter
=COUNTIF($B$2:$B$100,B2)>1, click Format, choose a fill colour and confirm.
In Google Sheets:
- Select B2:B100.
- Open Format > Conditional formatting.
- Under Format cells if, choose Custom formula is.
- Enter the same formula, choose a fill colour and click Done.
If your Excel uses semicolons between arguments, write =COUNTIF($B$2:$B$100;B2)>1. When the rule does not behave as expected, check three things:
- The selected range starts at B2, the same row the formula tests. A rule applied to a range that starts in another row tests the wrong cell.
- COUNTIF ignores upper and lower case, so "ab12" and "AB12" count as the same ID.
- Values that differ by a trailing space count as different, so a repeated ID can stay unmarked. Wildcard characters in IDs, such as * and ?, also change how COUNTIF matches.
Remove the duplicates afterwards
The highlight only shows the repeats. To remove them, copy the sheet first and use Data > Remove Duplicates in Excel, or Data > Data cleanup > Remove duplicates in Google Sheets.
For a CSV file, Clean Messy CSV Data cleans the file and reports what it changed. With the example data of the tool, the report shows 1 row removed by the step Remove duplicate rows, so you can compare that number with the number of highlighted cells.

To compare whole rows instead of one column, the generator also has the rule Duplicate rows (same values in every column). Keep the original file until you have compared the result. Rows that share an ID but differ in other columns may be two different records, and a duplicate rule on one column cannot tell the two cases apart.
Do it with your own data
Open the Conditional Formatting Generator, pick Duplicates in one column and enter the range of your ID column. Paste the formula into the rule dialog of Excel or Google Sheets, and check one highlighted ID by searching for it in the list.