ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • About
  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Data tools
  3. How to Prevent Duplicate Entries in Excel With Validation

How to Prevent Duplicate Entries in Excel With Validation

By ExcelReady Team·Updated November 3, 2026·6 min read

The short answer

Select the column, for example A2:A500, and open Data > Data Validation. Choose Custom and enter =COUNTIF($A$2:$A$500,A2)=1, then set the Error Alert style to Stop. Excel now refuses any entry that already appears in the list. The rule doesn't check values already there, so use Circle Invalid Data to find old duplicates.

Key takeaways

  • The rule =COUNTIF($A$2:$A$500,A2)=1 allows an entry only if it appears once in the whole range.
  • Lock the range with $ signs and leave A2 relative, written for the top cell of your selection.
  • Use the Stop error alert; Warning and Information let people keep the duplicate.
  • Validation doesn't check old data or pasted values. Use Circle Invalid Data and a COUNTIF check column.
  • COUNTIF ignores case and treats * and ? as wildcards, so use SUMPRODUCT or EXACT when that matters.
On this page+
  1. How to prevent duplicate entries with data validation
  2. Why the COUNTIF rule works
  3. Choose the right error alert
  4. Prevent duplicates across two columns
  5. Find duplicates already in the list
  6. Limits of the no-duplicates rule
  7. Practise it

To prevent duplicate entries in Excel, add a custom data validation rule with COUNTIF: =COUNTIF($A$2:$A$500,A2)=1. Excel then refuses any value that already appears in the column. This guide is for anyone who keeps a list of IDs, invoice numbers, emails or employee codes that must be unique. It goes further than the short rule in our data validation rules guide: how the formula works, which alert to choose, what to do about duplicates already in the list, and where the rule falls short.

How to prevent duplicate entries with data validation#

The rule is a custom formula that returns TRUE when an entry is allowed. Set it up like this:

  1. Select the cells to protect, starting from the top, for example A2:A500.
  2. Go to Data > Data Validation (Windows shortcut: Alt, A, V, V).
  3. Under Allow, choose Custom.
  4. In Formula, type =COUNTIF($A$2:$A$500,A2)=1.
  5. Open the Error Alert tab, choose Stop, and write a message such as "This invoice number is already in the list."
  6. Click OK.

Now type INV-1002 twice. The second time, Excel shows your message and refuses the entry. If you only need a fixed list of allowed values instead, a drop-down list is simpler.

Why the COUNTIF rule works#

COUNTIF counts how many cells in a range match a value. The rule counts how many times the new entry appears in the whole column, including the cell you just typed in. If the count is 1, the value is new. If it is 2 or more, it is a duplicate, the formula returns FALSE, and Excel blocks it.

Two details make it work in every row:

  • $A$2:$A$500 is locked. Every cell checks the same full range.
  • A2 is relative. You write the rule for the top cell, and Excel shifts it to A3, A4 and so on for the cells below.

If you write A$2 or $A$2 for the second part, every cell checks the value in A2 instead of its own value, and the rule stops making sense. The COUNTIF function guide explains the criteria argument in more detail.

Test the rule in a cell first#

Data validation gives no feedback while you write the formula, so test it next to the data. In C2, type =COUNTIF($A$2:$A$6,A2)=1 and fill down:

ABC
1Invoice noCustomerAllowed?
2INV-1001OlaTRUE
3INV-1002RajFALSE
4INV-1003KimTRUE
5inv-1002RajFALSE
6INV-1004OlaTRUE

Rows 3 and 5 return FALSE, because COUNTIF is not case-sensitive: INV-1002 and inv-1002 count as the same value. Once the results look right, copy the formula into the Custom box.

Choose the right error alert#

The Error Alert style decides whether people can override the rule. There are three:

StyleWhat happens when someone types a duplicate
StopThe entry is refused. They must change it or cancel.
WarningThey are asked "Continue?" and can keep the duplicate.
InformationThey see a note, and the duplicate is accepted.

Use Stop for real keys such as invoice numbers or employee IDs, where a duplicate breaks lookups and totals. Warning suits soft rules, such as a customer name that might legitimately repeat. Write a message that says what to do, for example "Invoice numbers must be unique. Check the list before you add a new one."

You can also add an Input Message, shown when the cell is selected, so people know the rule before they type.

Prevent duplicates across two columns#

Sometimes a value can repeat, but a combination can't. A customer can place many orders, but not two orders with the same order date and amount, for example. Use COUNTIFS with both columns and select A2:B500 before adding the rule:

Excel formula
=COUNTIFS($A$2:$A$500,$A2,$B$2:$B$500,$B2)=1

Note the $ before the column letters in $A2 and $B2. The rule applies to two columns, so without them, Excel would shift A2 to B2 for cells in column B and compare the wrong values. The guide to finding duplicates across two columns shows more combinations.

Find duplicates already in the list#

A new rule only checks values typed after you add it. Old duplicates stay where they are. Three ways to find them:

  1. Circle Invalid Data. Go to Data > Data Validation (arrow) > Circle Invalid Data. Excel draws a red circle around every cell that breaks the rule, so both copies of each duplicate are circled. Clear Validation Circles removes them.
  2. A check column. Keep the test formula from above, or use =COUNTIF($A$2:$A$500,A2)>1 to show TRUE on duplicates. Then filter that column for TRUE to see only the problem rows. The guide to filtering data shows how.
  3. Conditional formatting. Use Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values to colour them. See how to highlight duplicates.

To count how many values are repeated, =SUMPRODUCT(--(COUNTIF(A2:A6,A2:A6)>1)) returns 2 on the table above: both cells in the pair. Decide which copy is correct before deleting anything.

Limits of the no-duplicates rule#

Data validation guides people who type; it doesn't lock the data. Know where it falls short:

  • Pasting replaces the rule. Pasting a cell over a validated cell brings the pasted cell's validation, or none. Use Paste Special > Values (Windows: Ctrl+Alt+V; Mac: ⌃⌘V), and protect the sheet if the list matters.
  • Formulas aren't checked. Only typed values are validated, not results calculated by a formula.
  • Wildcards. COUNTIF treats * and ? as wildcards. An entry like INV-10* matches every invoice starting with INV-10, so it can be refused wrongly.
  • Long numbers. COUNTIF reads text that looks like a number as a number, and Excel keeps only 15 significant digits. Two different 16-digit card or account IDs can look like duplicates.
  • Text over 255 characters. COUNTIF returns #VALUE! for very long criteria, so long entries are refused.
  • Case. Case doesn't count. INV-1002 and inv-1002 are one value.

When wildcards, long numbers or case matter, compare the cells directly instead of using COUNTIF:

Excel formula
=SUMPRODUCT(--($A$2:$A$500=A2))=1
=SUMPRODUCT(--EXACT($A$2:$A$500,A2))=1

The first ignores wildcards and compares exact text. The second also respects capital letters. Both are slower on very large ranges, so keep the range to the rows you need instead of the whole column.

In an Excel table, the validation rule extends to new rows automatically. The formula can't use table names such as Table1[Invoice no] directly, so keep the plain range with a generous end row.

Practise it#

The rule is one COUNTIF, and spotting the duplicates it misses is a filtering job. Practise COUNTIF in a live spreadsheet, then practise filtering a table to review the rows your check column flags. ExcelReady checks each formula as you type. Start with the invoice test in the exercise on this page.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

Test the no-duplicates rule on row 5 before you use it. Click C5 and type =COUNTIF($A$2:$A$6,A5)=1, then press Enter. FALSE means the entry would be refused.

fx
ABCD
1
Invoice no
Customer
Allowed?
2
INV-1001
Ola
3
INV-1002
Raj
4
INV-1003
Kim
5
inv-1002
Raj
6
INV-1004
Ola
7
8
9

Tip: COUNTIF counts how many times A5 appears in the locked range. The entry is allowed only when that count is exactly 1.

Practise this in a lesson

LessonCOUNTIFCount the cells that match a condition, from exact words to number checks like ">=8".LessonFilter a tableTurn on filter buttons with Ctrl+Shift+L, filter by one or several values and by a number condition, total and count only the visible rows with SUBTOTAL, then clear the filters.Function guideCOUNTIFCount cells that match one condition with COUNTIF: text, numbers, wildcards and cell references. Real examples and a live exercise.

Frequently asked questions

How do I stop duplicate entries in an Excel column?

+

Select the column, go to Data > Data Validation, choose Custom and enter =COUNTIF($A$2:$A$500,A2)=1. Set the Error Alert style to Stop so Excel refuses any value that is already in the list.

Why does my no-duplicates rule still allow duplicates?

+

The rule only checks values typed into a cell. Pasted values replace the rule, old values are never checked, and Warning or Information alerts let people keep the duplicate. Also check that the range in the formula is locked with $ signs.

Can I prevent duplicates across two columns in Excel?

+

Yes. Use COUNTIFS with both columns, for example =COUNTIFS($A$2:$A$500,$A2,$B$2:$B$500,$B2)=1, applied to A2:B500. It blocks a row only when both values match an existing row.

Is the COUNTIF duplicate rule case-sensitive?

+

No. COUNTIF treats INV-1002 and inv-1002 as the same value, so the second one is refused. For a case-sensitive rule, use =SUMPRODUCT(--EXACT($A$2:$A$500,A2))=1.

How do I find duplicates that were entered before I added the rule?

+

Go to Data > Data Validation (arrow) > Circle Invalid Data. Excel circles every cell that breaks the rule, including both copies of each duplicate.

Sources

  • Apply data validation to cells - Microsoft Support
  • COUNTIF function - Microsoft Support
  • Find and remove duplicates - Microsoft Support

Written and checked by the ExcelReady Team. First published November 3, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. How to prevent duplicate entries with data validation
  2. Why the COUNTIF rule works
  3. Choose the right error alert
  4. Prevent duplicates across two columns
  5. Find duplicates already in the list
  6. Limits of the no-duplicates rule
  7. Practise it

Keep reading

Data tools· 5 min read

Create a Drop-Down List in Excel

To create a drop-down list in Excel, select the cells, go to Data > Data Validation, set Allow to List, and in Source either type the items separated by commas (Open,Closed) or select a range that holds them. Click OK. Each cell now shows an arrow, and Excel rejects entries that aren't on the list.

Data tools· 6 min read

Find and Highlight Duplicates in Excel

To highlight duplicates in Excel, select the cells, go to Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values, and click OK. Every value that appears more than once turns red. To flag or count repeats with a formula instead, use COUNTIF: =COUNTIF($A$2:$A$9,A2)>1 is TRUE for a duplicate.

Data tools· 6 min read

Find Duplicates Between Two Columns in Excel

To find duplicates between two columns in Excel, check each value in the first column against the second with COUNTIF: =COUNTIF($B$2:$B$9,A2)>0 returns TRUE when A2 also appears in column B. Fill it down, or use the same test as a conditional formatting rule to highlight the matches. In Excel 2021 or Microsoft 365, FILTER can list them all.

More on data tools

  • How to Make a Radar Chart in Excel to Compare Scores
  • How to Reference Another Sheet in Excel
  • How to Refresh a Pivot Table (and Why It Doesn't Update)
  • How to Remove Duplicates in Excel (3 Ways)
  • Make a Scatter Plot in Excel to Show a Relationship
  • How to Make a Searchable Drop-Down List in Excel
All data tools articles →

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free