- To post as a guest, your comment is unpublished.· 4 months agoPlease try below formula:
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.
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:
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.
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:
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
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:
3. Then click OK button, the duplicate value will be deleted.
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:
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:
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:
More than 200 functions can make your job efficiently,you can download Kutools for Excel for free trail.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
- To post as a guest, your comment is unpublished.· 7 months agothis formula didn't work =COUNTIF($A:$A,A2)<2