malas
malas

Reputation: 2137

Excel VBA read validation list into variable

I was trying to find an Excel VBA code that reads validation list into a variable.

I'm using Excel 2010 version.

In the code below I'm dynamically setting up values using variable qNR, and appears in dropdown menu. Later I need to read values in validation list, remove or update certain values and set new values.

I cannot find any example code that reads validation list into a variable.

With Selection.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:=qNR
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True

End With

Thank you!

Upvotes: 1

Views: 13720

Answers (1)

Aaron Thomas
Aaron Thomas

Reputation: 5281

Assuming it's a list type (validation type 3), then Debug.Print Range(yourRange).Validation.Formula1 should print out a list. So Object.Validation.Formula1 would appear to work for you. See here for more info.

Upvotes: 2

Related Questions