Data Validation - Duplicate Entries using a defined list

mizogy

New Member
Joined
Jul 5, 2011
Messages
40
Office Version
  1. 365
Platform
  1. Windows
Hi All

Here is the conundrum:

(1) I am using a data validation list to provide the user a defined list of options to select from the drop-down list
(2) This validation table is applied to cells A1:A10
(2) However, I want to avoid them making duplicate selections from the drop-down list in proceeding cells, for example, if they selected 'Apples' from the drop-down list in cell A1, I want to prevent them being able to select 'Apples' again from the drop-down list in the remaining cells A2 to A10.

Any ideas and solutions, most welcome!

Best, Mizogy
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Make a selection in A1 and then in any cell in A2:A10.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Column <> 1 Then Exit Sub
    If Intersect(Target, Range("A2:A10")) Is Nothing Then Exit Sub
    If Target = Range("A1") Then
        MsgBox ("You cannot select the value of cell A1.  Please try again.")
        Target.ClearContents
    End If
End Sub
 
Upvote 0
Private Sub Worksheet_Change(ByVal Target As Range) If Target.CountLarge > 1 Then Exit Sub If Target.Column <> 1 Then Exit Sub If Intersect(Target, Range("A2:A10")) Is Nothing Then Exit Sub If Target = Range("A1") Then MsgBox ("You cannot select the value of cell A1. Please try again.") Target.ClearContents End If End Sub
Thanks Mumps. I want to avoid there being any duplication in the range, for example it could be that 'Oranges' is selected in A2 and A4 from the available drop-down list in each of the cells. I want to avoid there being any duplication in Range A1 to A10.
 
Upvote 0
Try:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Column <> 1 Then Exit Sub
    If Intersect(Target, Range("A1:A10")) Is Nothing Then Exit Sub
    Application.EnableEvents = False
    If WorksheetFunction.CountIf(Range("A1:A10"), Target) > 1 Then
        MsgBox (Target & " has already been selected.  Please try again.")
        Target.ClearContents
    End If
    Application.EnableEvents = True
End Sub
 
Upvote 0
Solution
Try:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Column <> 1 Then Exit Sub
    If Intersect(Target, Range("A1:A10")) Is Nothing Then Exit Sub
    Application.EnableEvents = False
    If WorksheetFunction.CountIf(Range("A1:A10"), Target) > 1 Then
        MsgBox (Target & " has already been selected.  Please try again.")
        Target.ClearContents
    End If
    Application.EnableEvents = True
End Sub
Thanks Mump, my apologies for my delayed reply, was on AL :)
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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