Data validation: Value "b" in another cell allows any value

tohtorisalainen

New Member
Joined
Sep 3, 2013
Messages
2
If value of cell A1 is "a", then I want data validation (list of choices) for cell B1.
If value of cell A1 is "b", then any value can be entered into cell B1.

Data validation doesn't automatically support this.

How to do this?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
here is a macro that might help:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$1" And Range("A1").Value = "a" Then
        With Range("B1").Validation
            .Delete
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=$C$1:$C$5"
            .IgnoreBlank = True
            .InCellDropdown = True
            .ShowInput = True
            .ShowError = True
        End With
    ElseIf Target.Address = "$A$1" And Range("A1").Value <> "a" Then
        Range("B1").Validation.Delete
    End If
End Sub

basically whenever you change the value of A1 to "a" it will enable validation for B1 and will use the cells "C1:C5" as the list of allowed values, if you change A1 to anything other that "a" the validation is disabled
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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