Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Ensuring Unique Values in a Column.

Ensuring Unique Values in a Column

by Allen Wyatt
(last updated June 16, 2017)

13

When you are entering information in a worksheet, you may want to ensure that the data being entered is actually unique for a particular column. For instance, if you are entering a series of invoice numbers in column D of a worksheet, you may want to ensure that you don't enter the same invoice number twice.

There are a couple of ways that you can approach such a problem. If you are always entering your new information at the bottom of a column, you can use Excel's data validation feature to make sure that whatever you are entering in the current cell does not match anything higher up in the column. Simply follow these steps:

  1. Select column D.
  2. Choose Validation from the Data menu. Excel displays the Data Validation dialog box. (See Figure 1.)
  3. Figure 1. The Data Validation dialog box.

  4. Using the Allow drop-down list, choose the Custom option.
  5. In the Formula box, enter the following formula:
  6.      =MATCH(D1,$D:$D,0)=ROW(D1)
    
  7. Click on OK.

If you may be entering data anyplace within column D, and you want to know if you are entering a value that is elsewhere in the column (above or below the current cell), then you can follow the above steps, but use this formula in step 4:

=COUNTIF($D:$D,D1)<2

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2650) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Ensuring Unique Values in a Column.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Converting Tables to Charts

Put numeric information in a table and you can then convert that information to a graphical chart using Microsoft Graph ...

Discover More

Extra Spaces after Inserting a Building Block

Building blocks are a great tool for inserting standard information in your documents. It is also possible, however, to get ...

Discover More

Cleaning Scummy Shower Doors

Do you have glass shower doors that always seem to be covered with a soapy film? Here's a great cleaning idea that can once ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (menu)

Stopping Validated Data from being Overwritten

Data Validation is a great tool to make sure that data entered in a cell meets whatever criteria you decide. Its weakness, ...

Discover More

Limiting Input to a Format

When setting up a worksheet for others to use, you might want to make some limitations on what can be entered in certain ...

Discover More

Changing Fonts in Data Validation Drop-Down Lists

The data validation capabilities of Excel allow you to easily create drop-down lists showing what data is acceptable for a ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 1?

2017-03-09 12:05:30

Clint

Yay!


2016-05-06 11:41:51

Jenni

This formula worked great when I tested it in a blank excel worksheet. But, when I tried it within my existing table it did not work :( Got any idea of how to get it to work in a table? Seems like there's a lot of things that don't work well within a table in excel. Thanks, Jenni


2016-01-23 13:07:31

Kadr Leyn

Thanks for tutorial.

Vba codes can be used in this topic:

"Excel Data Validation List With Unique Values"

Template's video :https://www.youtube.com/watch?v=LiIpObVus7o


2016-01-13 12:33:01

mac

I must be missing something?
running MS Office 2016
not getting any messages


2015-11-23 08:08:53

billyg

Thanks!!


2015-08-12 19:19:22

manpreet

I want to avoid duplicate data in a comibnation of columns like

Valid Data
Date | Shift
08 Aug | Night
08 Aug | Day

Example of INVALID data
Date | Shift
08 Aug | Night
08 Aug | Night

So I have to avoid entry of duplicate data in a combination of columns. I am not able to figure it out please help.


2015-06-16 02:53:38

sachi

thank you for this tip


2014-08-18 02:30:57

Akshay

Thanks for the tip!


2013-11-14 07:47:21

Michael (Micky) Avidan

@Yesenia,

In order to avoid duplicate typing and/or copying - try th following Event-macro to be placed in the Worksheets module.
The "traditional" Data Validation is not needed in that case.

*** The macro refers to Column "A".

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim C As Range, i As Long
If Not Intersect(Target, Me.[A:A]) Is Nothing Then
Application.EnableEvents = False
For Each C In Target
If C.Column = 1 And C.Value > "" Then
If WorksheetFunction.CountIf(Me.[A:A], C.Value) > 1 Then
i = C.Interior.ColorIndex
f = C.Font.ColorIndex
C.Interior.ColorIndex = 3 ' Red
C.Font.ColorIndex = 6 ' Yellow
C.Select
MsgBox "Watch Out !!! - Duplicate Entry !", vbCritical, "Error"
C.ClearContents
C.Interior.ColorIndex = i
C.Font.ColorIndex = f
End If
End If
Next
Application.EnableEvents = True
End If
End Sub

Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2014)
ISRAEL


2013-11-13 22:37:09

Ole

Hi Allen,

I thought to let you know that the current formula I am using is:

=COUNTIF($C$3:$C$1001,C3)<=1

Kind Regards,
Ole


2013-11-13 22:35:21

Ole

Hi Allen,

Thanks for your tips regarding unique values in a column - worked a treat.
I wanted to extend this info and allow unique values for the column cell range based on a list.
I have already created a form combo box with a list of four values that are in the column N1, N2, N3 and N4.
I would like the unique values only based on the selection in the drop down list.
Can you help me?

Kind Regards,
Ole


2013-06-10 14:50:48

Yesenia Bernal

Hello Allen,

I tried you how to enter values in a column and it worked great. I just have a question it there's a way for it to when you paste numbers not just entered numbers.

Thank you,
Yesenia Bernal


2012-06-02 15:40:39

Elaine Wilson

Thank you such a useful formula


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.