Data validation formula in cell and list?

S

Suzanne

Good morning. I'd like to have formula in B2 that returns NA if B1 is No, if
B1 is Yes, i'd like to force drop down selection or validation in B2 of
Yes/No - is this possible?

A B
1 Was it cold enough to snow? Yes/No
2 Did it snow? =if(B1="No",NA)
 
S

Stefi

You need an event sub for that, something like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "B1" Then
If Target.Value = "No" Then
Range("B2").Validation.Delete
Range("B2").Value = "NA"
Else
Range("B2").Value = ""
Range("B2").Validation.Delete
Range("B2").Validation.Add Type:=xlValidateList,
AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="Yes,No"
Range("B2").Select
End If
End If
End Sub

Regards,
Stefi


„Suzanne†ezt írta:
 
S

Stefi

You are welcome! Thanks for the feedback! Please post the result of the try!
Stefi

„Suzanne†ezt írta:
 
S

Suzanne

Again thanks for your help, this is quite new to me. I pasted your code in
my vb editor and made the adjustments to the target cells:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "i71" Then
If Target.Value = "No" Then
Range("i72").Validation.Delete
Range("i72").Value = "NA"
Else
Range("i72").Value = ""
Range("i72").Validation.Delete
(HERE) Range("i72").Validation.Add Type:=xlValidateList,
AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="Yes,No" (-- TO HERE APPEARS IN RED
FONT
Range("i72").Select do i still need
a list or the list is the
End If "Yes,No"
in the code? THANKS!)
End If
End Sub
 
S

Stefi

The forum's editor can't handle long code lines properly, I inserted a line
separator to split up long line:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "I71" Then
If Target.Value = "No" Then
Range("I72").Validation.Delete
Range("I72").Value = "NA"
Else
Range("I72").Value = ""
Range("I72").Validation.Delete
Range("I72").Validation.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="Yes,No" 'this is the list built in the
code
Range("I72").Select
End If
End If
End Sub

Don't forget to paste the code in the worksheet code window (NOT in a normal
module!)

Stefi


„Suzanne†ezt írta:
 

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