ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   data validation (https://www.excelbanter.com/excel-worksheet-functions/15707-data-validation.html)

Meliisa

data validation
 
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

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

---
HTH
Jason
Atlanta, GA

-----Original Message-----
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
.



All times are GMT +1. The time now is 03:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com