data validation

M

Meliisa

Hi
I have 2 cells that I would like to apply the same data validation list to.
However, the cells cannot equal each other. How do I apply the list and <>
both to the cells?
Thansk for all replies
Melissa
 
J

Jason Morin

Set up your validation list for both A1 and B1. Then
right-click on the worksheet tab, select "View Code", and
paste in the code below. Press ALT+Q to close:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Application
If Intersect(Target, [B1]) Is Nothing Then GoTo CheckA1
.EnableEvents = False
With Target
If .Value = .Offset(0, -1).Value Then
MsgBox "List selections cannot be the same!"
.Value = ""
End If
End With
.EnableEvents = True
Exit Sub
CheckA1:
If Intersect(Target, [A1]) Is Nothing Then Exit Sub
.EnableEvents = False
With Target
If .Value = .Offset(0, 1).Value Then
MsgBox "List selections cannot be the same!"
.Value = ""
End If
End With
.EnableEvents = True
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top