Skip to main content
 

 How to only allow unique values in Excel?

Author: Xiaoyang Last Modified: 2024-09-23

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 Kutools for Excel

Only allow unique values in worksheet with VBA code


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:

click Data > Data Validation > Data Validation

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.

specify options in the Data Validation dialog box

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:

when entering duplicate value into the specific column, a warning message will pop out


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 offers over 300 advanced features to streamline complex tasks, boosting creativity and efficiency. Enhanced with AI capabilities, Kutools automates tasks with precision, making data management effortless. Detailed information of Kutools for Excel...         Free trial...

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:

click Prevent Duplicate feature of kutools

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

a warning message popps out to remind you the Data Validation will be remove if applying this feature

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:

another prompt box is popped out to remind which cells have been applied this feature

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:

when entering some duplicate data, a warning message will appear

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


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

click View Code and insert vba code into the module

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:

a warning message is popped out to remind the duplicate entry is not allowed

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

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...


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!