Prevent users from entering Duplicate Data

kiwikiki718

Board Regular
Joined
Apr 7, 2017
Messages
80
Office Version
  1. 365
Platform
  1. Windows
I created a VBA code that will prevent users from selecting duplicate data from a drop down list in column C of my excel spreadsheet, however I want users to be able to select "Other" in multiple fields without receiving an error.

Here is the code that I have written but need to show how to exclude the selection "Other".

Private Sub worksheet_change(ByVal Target As Range)
If Application.CountIf(Range("C:C"), Target) > 1 Then
MsgBox "Duplate Custom field Selected!", vbCritical, "Remove Data"
Target.Value = ""
End If
End Sub

thank you in advance
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Perhaps this?

Rich (BB code):
Private Sub worksheet_change(ByVal Target As Range)
If Application.CountIf(Range("C:C"), Target) > 1 Then
If Target.Value <> "Other" Then
MsgBox "Duplate Custom field Selected!", vbCritical, "Remove Data"
Target.Value = ""
End If
End If
End Sub
 
Upvote 1
Solution
Perhaps this?

Rich (BB code):
Private Sub worksheet_change(ByVal Target As Range)
If Application.CountIf(Range("C:C"), Target) > 1 Then
If Target.Value <> "Other" Then
MsgBox "Duplate Custom field Selected!", vbCritical, "Remove Data"
Target.Value = ""
End If
End If
End Sub

Great, this worked! Thank You!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top