Skip to main content

 How to only allow unique values in Excel?

If you want to keep only unique values entering in a column of worksheet and prevent the duplicates, this article will introduce some quick tricks for you to deal with this task.

Only allow unique values in worksheet with Data Validation

Only allow unique values in worksheet with VBA code

Only allow unique values in worksheet with Kutools for Excel


Only allow unique values in worksheet with Data Validation

In fact, the Data Validation function of Excel can help you to solve this problem, please do as follows:

1. Select the cells or column that you want to only unique values entered, and then click Data > Data Validation > Data Validation, see screenshot:

doc only allow unique 1

2. In the Data Validation dialog box, please do the following operations:

(1.) Click the Settings tab;

(2.) Under the Allow drop down list, choose Custom;

(3.) And enter this formula: =COUNTIF($E:$E,E1)<2 (E is the column that you want to only allow unique values, E1 is the first cell of the column you want to use) into the Formula text box.

doc only allow unique 2

3. And then click OK button, from now on, when you enter duplicate value into the specific column you set, a warning message will pop out to remind you, see screenshot:

doc only allow unique 3


Only allow unique values in worksheet with VBA code

If you are interested in the VBA code, the following code also can do you a favor.

1. Right click the sheet tab that you want to allow only negative numbers, and choose View Code from the context menu, in the popped out Microsoft Visual Basic for Applications window, please copy and paste the following code into the blank Module:

VBA code: Only allow unique values in worksheet:

Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice 20160829
  Dim xRg As Range, iLong, fLong As Long
  If Not Intersect(Target, Me.[A1:A1000]) Is Nothing Then
     Application.EnableEvents = False
     For Each xRg In Target
     With xRg
         If (.Value <> "") Then
          If WorksheetFunction.CountIf(Me.[A:A], .Value) > 1 Then
            iLong = .Interior.ColorIndex
            fLong = .Font.ColorIndex
            .Interior.ColorIndex = 3
            .Font.ColorIndex = 6
            MsgBox "Duplicate Entry !", vbCritical, "Kutools for Excel"
            .ClearContents
            .Interior.ColorIndex = iLong
            .Font.ColorIndex = fLong
          End If
       End If
     End With
     Next
     Application.EnableEvents = True
  End If
End Sub

doc only allow unique 4

Note: In the above code, the A1:A1000 is the column cells that you want to prevent duplicate.

2. Then save and close this code, now, when you enter duplicate values in cell A1:A1000, a warning message is popped out to remind you the duplicate entry is not allowed, see screenshot:

doc only allow unique 5

3. Then click OK button, the duplicate value will be deleted.


Only allow unique values in worksheet with Kutools for Excel

The above two methods only can prevent the duplicate entries in one column, if you have Kutools for Excel, its Prevent Duplicate utility can help you quickly prevent duplicate in a range of cells and only one column or row.

Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. 

After installing Kutools for Excel, please do as follows:

1. Select the column or range of cells which you want to prevent the duplicate values but allow only unique data.

2. Then click Kutools > Prevent Typing > Prevent Duplicate, see screenshot:

3. And a warning message will pop out to remind you the Data Validation will be remove if applying this feature, see screenshot:

doc only allow unique 7

4. Then click Yes button to continue, and another prompt box is popped out to remind you which cells have been applied this feature. See screenshot:

doc only allow unique 8

5. And then click OK button, now, when you enter some duplicate data in range A1:D15, a prompt box is displayed to remind you the duplicate data is not valid, you need to only enter the unique value. See screenshot:

doc only allow unique 9

More than 200 functions can make your job efficiently,you can download Kutools for Excel for free trail.


Demo: Only allow unique values in worksheet with Kutools for Excel

Kutools for Excel: with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. Download and free trial Now!

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

Description


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Comments (3)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I was expecting the formula would work when you paste too. But for me it only works if I type. When typing a value that is not unique I see the error massage and I'm not allowed to continue. Which is great. However, if I paste the value, no error message appears. Is that expected, or I am doing something wrong?
This comment was minimized by the moderator on the site
this formula didn't work =COUNTIF($A:$A,A2)<2
This comment was minimized by the moderator on the site
Please try below formula:

=COUNTIF($A:$A,A1)<2
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations