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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
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,215,325
Messages
6,124,252
Members
449,149
Latest member
mwdbActuary

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