1

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!

1
  • Validation lists can't do all the things you would expect from a ListBox. Trying to make an Excel sheet function as a form is a frustrating experience. Use WinForms where you can. Maybe use Access instead. Commented Nov 6, 2018 at 17:02

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Worked using Target.Validation.Formula1. Thanks you very much Aaron
Object.Validation.Formula1 returns a formula associated with a Validation object. @malas, how do you print the list? What is Target?
@Aaron Thomas Both links are broken

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.