You can prevent duplicates in Excel by setting up a Data Validation rule that uses the COUNTIF function to check for repeated entries automatically. This approach protects data integrity, keeps your spreadsheets cleaner and eliminates the need for tedious manual checks. The walkthrough below shows you exactly how to set it up step by step. This method works in Excel 2016, 2019, 2021 and Microsoft 365.
Follow these steps to create a Data Validation rule that blocks Excel duplicate data entry across a range of cells.
One) Select the range of cells where you want to prevent duplicate values (in this example, B3:B20). .
2) In Excel, on the Data tab, click Data Validation.
3) Once in the Data Validation dialog box, under the Settings tab click the Allow dropdown and select Custom from the list. A Formula field will appear.
4) In the Formula field type =COUNTIF($B$3:$B$20,B3)<2. When data is entered into a cell, this formula is evaluated. It looks for duplicate values.

See the sections below for a detailed breakdown of how this formula works and why the reference types matter.
The formula =COUNTIF($B$3:$B$20,B3)<2 is the engine behind the duplicate prevention rule. Here is what each part does:
In plain language, the formula asks: "Does this value already appear in my list?" If the answer is yes, Excel blocks the entry.
Getting the references right is the most common stumbling point when setting up this rule. Here is a quick comparison:
| Absolute Reference | Relative Reference | |
|---|---|---|
| Syntax | $B$3:$B$20 | B3 |
| Behavior | Stays locked on the same range no matter which cell is active | Adjusts automatically to match the current row |
| When to Use | For the validation range so every cell checks against the full list | For the active cell argument so each row evaluates its own value |
Absolute references are required for the range ($B$3:$B$20) because you want every cell in the validated area to compare against the entire list, not a shifting subset. The active cell reference (B3) must remain relative so it updates per row. If you accidentally lock both references, the formula will only ever check the value in B3 and the rule will not work correctly.
5) In the Data Validation dialog, click the Input Message tab and, if desired, type a message that will be displayed when the user selects a cell within the range of the Data Validation rule. Otherwise, if you don't want a message to appear every time someone selects a cell in the range, clear the 'Show input message...' option.
6) Click the Error Alert tab and type the message that will be displayed if the user enters a duplicate value in the range. Under the Style dropdown you will see three options: Stop, Warning and Information. Select Stop if you want to fully block duplicate entries. The Warning and Information styles display a message but still allow the user to override and enter the duplicate.
Best practices for writing clear error alert messages:
7) Click OK.
Now test your Data Validation rule by entering values, including some duplicates, within the range.
This technique is useful any time a column must contain only unique values. Common workplace use cases include:
Once your rule is in place, keep these tips in mind:
Pryor Learning offers Excel training courses that cover Data Validation, formulas and other productivity techniques in depth. Whether you are building your first spreadsheet or streamlining complex workflows, structured training can help you get more from Excel faster.