Today I'll tell you how to prevent duplicates from appearing in a column of your Excel worksheet. This tip works in Microsoft Excel 365, 2021, 2019, 2016, and lower.
We covered a similar topic in one of our previous articles. So you should know how to automatically highlight duplicates in Excel once something has been typed.
This article will help you stop duplicates appearing in one or several columns in your Excel worksheet. So you can have only unique data in the 1st column of your table be there invoice numbers, stock keeping units, or dates, each mentioned only once.
How to stop duplication - 5 easy steps
Excel has Data Validation - one unfairly forgotten tool. With its help you can avoid errors occurring in your records. We will be sure to devote some future articles to this helpful feature. And now, as a warm-up, you will see a simple example of using this option. :)
Suppose, you have a worksheet named "Customers" that includes such columns as Names, Phone numbers, and Emails you use for sending newsletters. Thus all email addresses must be unique. Follow the steps below to avoid sending the same message to one client twice.
- If necessary, find and delete all duplicates from the table. You can first highlight the dupes and delete them manually after looking through the values. Or you can remove all duplicates with the help of the Duplicate Remover add-in.
- Select the entire column where you need to avoid duplicates. Click on the first cell with data keeping the Shift keyboard button pressed and then select the last cell. Or simply use the combination of Ctrl + Shift + End. It is important to select the 1st data cell first.
Note: If your data are in a simple Excel range as opposed to a full-fledged Excel table, you need to select all the cells in your column, even the blank ones, from D2 to D1048576
- Go to Excel "Data" tab and click on the Data Validation icon to open the dialog box.
- On the Settings tab, choose "Custom" from the Allow drop down list and enter
=COUNTIF($D:$D,D2)=1
into the Formula box.Here $D:$D are the addresses of the first and the last cells in your column. Please pay attention to the dollar signs that are used to indicate absolute reference. D2 is the address of the first selected cell, it is not an absolute reference.
With the help of this formula Excel counts the number of occurrences of the D2 value in the range D1:D1048576. If it is mentioned just once, then everything is fine. When the same value appears several times, Excel will show an alert message with the text you specify on the "Error alert" tab.
Tip: You can compare your column with another column to find duplicates. The second column can be on a different worksheet or event workbook. For example, you can compare the current column with the one that contains the blacklisted emails of customers
you don't won't to work with any longer. :) I will give more details about this Data Validation option in one of my future posts. - Switch to the "Error alert" tab, and enter your text into the fields Title and Error message. Excel will show you this text as soon as you try to enter a duplicate entry into the column. Try to type the details that will be accurate and clear for you or your colleagues. Otherwise, in a month or so you can forget what it means.
For example:
Title: "Duplicate email entry"
Message: "You have entered an email address that already exists in this column. Only unique emails are allowed." - Click OK to close the "Data validation" dialog.
Now when you try to paste an address that already exists in the column, you will see an error message with your text. The rule will work both if you enter a new address into an empty cell for a new customer and if you try to replace an email for the existing client:
If your "No duplicates allowed" rule can have exceptions :)
On the fourth step choose Warning or Information from the Style menu list. The alert message behavior will change correspondingly:
Warning: The buttons on the dialog will turn as Yes / No / Cancel. If you click Yes, the value you enter will be added. Press No or Cancel to get back to editing the cell. No is the default button.
Information: The buttons on the alert message will be Ok and Cancel. If you click Ok (the default one), a duplicate will be added. Cancel will take you back to the editing mode.
Note: I'd like to pay your attention again to the fact that the alert about a duplicate entry will appear only when you try to enter a value into a cell. Excel will not find existing duplicates when you configure the Data Validation tool. It will not happen even if there are more than 150 dupes in your column. :).
12 comments
Manually entering duplicate values in this case seems to work, such as entering "123". When I input the data manually, it works fine. However, when I try to copy and paste the data, the cell accepts it, indicating that the data validation is not functioning properly in this scenario.
Hi! Unfortunately, validating data in Excel only works when typing. In your case, you need to use a VBA macro to check values when a cell changes.
First of all thanks for this great services you offer many end-users out there.
Secondly, I have a question in relation to a searchable database in Excel where a Pivot Table is used, and a "Remove Duplicate" is ticked. Now assume that a business wants to keep records of the usage a vehicle whose registration number is N111-222W which was used by different staff members from 01 July 2023 to 30 July 2023. In the vehicle registration number the number N111-222W has to appear repeatedly by default, how can I record the usage history without duplicating the registration number?
Regards,
Reha
Hi! If you are using a Pivot Table, place the vehicle number in the Field Section. You can also extract data by condition using the FILTER function. Use only the columns you need in the formula. I hope it’ll be helpful.
Hi,
I am creating a time sheet for my team to use and I have three columns that I want to prevent people from entering the same data in the columns are time off/holiday leave, alternate work schedule day and comp time used. If somebody puts 8.25 in the alternate work schedule column I don’t want them to be able to put anything in the other two columns for that same day. And if somebody puts 8.25 in the time off column I don’t want anyone to be able to put that same value in either of the other columns for that same day. I hope that makes sense so far the formulas I’ve tried I haven’t worked. Is there a way to do this? Thank you so much
Hello!
If I understand the problem correctly use the data validation tool with these formulas
=((A1<>B1)*(A1<>C1)*(B1<>C1))+(COUNTBLANK(A1:C1)>1)
or
=(COUNTIF(A1:C1,A1)+COUNTIF(A1:C1,B1)+COUNTIF(A1:C1,C1))<4
The column I wish to eliminate the entry of duplicates is populated by alphanumeric characters. The formula =COUNTIF($A$1:$A$20,A1)=1 does NOT work:
- direct data entry (typing) meets automatic error message
- copy date entry is permitted even if the same date already in the column.
Excel 2016 - So what IS the correct, working method to prohibit duplicate entries?
Hello Rottweiller!
Unfortunately, Data Validation does not always work (it is mentioned in the last paragraph of the article).
It works only when you put information directly into a cell and press Enter to record changes at the end. If you replace data in a cell by copying or pasting another cell, Data Validation does not see those changes and cannot ban them.
I recommend using Conditional Formatting to see such duplicates.
You can use this formula as a condition: =COUNTIF($A$1:$A$20,A1)>1.
Alternatively, simply use standard Highlight Cell Rules -> Duplicate Values
how to validate name field in excel(cell should not accept number or special characters )?
Hey Josh,
please check this article out: how to apply data validation to cells
How to prevent duplicate numeric and text entries in excel column, only unique numeric and text data allowed. above formula: example =countif($D:$D,D2)=1 is working for both numeric and text value to prevent duplicate.
My question are below:
1. How to prevent duplicate only Numeric entries in excel column, only Unique Numeric data allowed.
2. As well as how to prevent duplicate only text entries in excel column, only Unique text data allowed.
Kindly do the reply needful.
Regards
Pradeep Kumar
Please specify what result you want to get. This formula works for text as well as for numeric data.
If you want to allow only unique numbers, text can be repeated, then use this formula:
=OR(ISNUMBER(D2)=FALSE, countif($D:$D,D2)=1)
If only unique text is allowed (numbers can duplicate), then the formula will be as follows:
=OR(ISNUMBER(D2)=TRUE, countif($D:$D,D2)=1)
If you want to get something different, please give me more details.