Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

 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 60 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:

doc only allow unique 6

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 200 handy Excel add-ins, free to try with no limitation in 60 days. Download and free trial Now!



Recommended Productivity Tools for Excel

Kutools for Excel Helps You Always Finish Work Ahead of Time, and Stand Out From Crowd

  • More than 300 powerful advanced features, designed for 1500 work scenarios, increasing productivity by 70%, give you more time to take care of family and enjoy life.
  • No longer need memorizing formulas and VBA codes, give your brain a rest from now on.
  • Become an Excel expert in 3 minutes, Complicated and repeated operations can be done in seconds, 
  • Reduce thousands of keyboard & mouse operations every day, say goodbye to occupational diseases now.
  • 110,000 highly effective people and 300+ world-renowned companies' choice.
  • 60-day full features free trial. 60-day money back guarantees. 2 years of free upgrade and support.

Brings Tabbed Browsing and Editing to Microsoft Office, Far More Powerful Than The Browser's Tabs

  • Office Tab is designed for Word, Excel, PowerPoint and Other Office Applications: 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!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.

Be the first to comment.