Prevent Duplicate Entries In A Data Range Using Data Validation and The COUNTIF Formula


Sometimes is is not enough to just highlight duplicate values using conditional formatting in Excel, sometimes you just do not want to allow users to enter duplicates. For example if you are collecting customer numbers which are unique and duplicates would mean that the customer list is incorrect.

It is easy to prevent users entering duplicates with a simple formula within Data Validation.

  • Highlight the cells you want to apply the validation to (in our exmaple it is A2 to A10)
  • Data Tab – Data Tools Group- Data Validation – Settings – Custom

This brings us to the area where we can specify a formula to prevent data duplicates

avoid dupes data validation1

 

We use the COUNTIF function which has two parts to it.

range – the range of cells we want to count
criteria – this can be a number, expression, cell reference, or text string that determines which cells will be counted.

The formula looks like this

avoid dupes data validation3

The formula counts the number of cell in our range $A$2:$A$10 that are equal to the value in A2. (we have made the range of cells A2:A10 absolute or fixed using the $ sign.

By adding the =1 we are specifying they can occur only once. Because we selected the range A2:A20 before we clicked on Data Validation, Excel automatically copies the formula to the other cells.

Let’s test it.

avoid dupes data validation4

It works!. The user cannot enter a duplicate account number.

Extra Tip- to enter an input message and error alert message, go to the Input Message and Error Alert tab.

 

WANT TO WATCH THE VIDEO?

More Excel Tips

MR Xl 40 formulas

excel-formulas-ad-5

Barbara

Barbara is an experienced data analyst with over 20 years of experience. Author of the How To Excel At Excel Top 50 Excel tips Ebook, YouTuber and Excel Blogger.

Recent Posts