Apply Data Validation with VBA

Gliffix101

Board Regular
Joined
Apr 1, 2014
Messages
81
Hey All,

Looking for some help here. I have two cells: C46 and E46. In Cell C46 I have a data validation based on named range "Headers". What I'm looking to do is that once a user selects an option in C46, the VBA applies a data validation in E46 with a previously defined named range. For example: If user selects drop down C46 = "Specialist", then E46 should apply data validation with the named range "LS". The macro will not define the named range as I have this defined within the Excel workbook. I've been working through the code from previous posts, but it's just not applying the validation. Any help would be appreciated:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
      
    If C46 = "Loan Specialist" Then
        With E46.Validation
            .DELETE
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=LS
            .IgnoreBlank = True
            .InCellDropdown = True
            .InputTitle = ""
            .ErrorTitle = ""
            .InputMessage = ""
            .ErrorMessage = ""
            .ShowInput = True
            .ShowError = False
        End With
    End If


End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
You can do this with Dependent Named ranges.

You already have the Named Range LS, so select E46 and define a new Name

Name:= Foo RefersTo = =IF($D46="Specialist", LS)

Then put List style Data Validation on E46 with the source =Foo
 
Upvote 0
So simple! I have 9 validation points, so I was trying to input the formula initially into the Data Validation formula. Never even thought to put the IF statement as part of the named range! Now I see why you're an MVP! Thanks Mike!!!
 
Upvote 0

Forum statistics

Threads
1,224,901
Messages
6,181,638
Members
453,059
Latest member
jkevin

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