How to get VBA t read every value from a dell with data validation list

xicoandrade

New Member
Joined
Feb 20, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Dear all, help!
I need VBA do read every vale from a cell that contains a data validation list the is defined by a given range.

I notice in the past WarPigl3t posted the following code for a similar question (btw, very neat!!).

Sub loopthroughvalidationlist()
validationListValues = Range("A3").Validation.Formula1
myDelimiter = ", "
mySplit = Split(validationListValues, myDelimiter)
For Each element In mySplit
MsgBox element
Next element
End Sub


Unfortunately this code works only when the datavalidation dropdown list is fixed (i.e. contains fixed values instead of linked to a range of cells).

In my case the list of items on the datavalidation dropdown list is defined by a range, such as the image below.

1645376296584.png


Can anyone help?
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi and welcome to MrExcel.

How about:

VBA Code:
Sub loopthroughvalidationlist()
  Dim c As Range
  For Each c In Range(Range("A3").Validation.Formula1)
    MsgBox c.Value
  Next
End Sub
 
Upvote 0
Solution
Dim c As Range For Each c In Range(Range("A3").Validation.Formula1) MsgBox c.Value Next
Hi and welcome to MrExcel.

How about:

VBA Code:
Sub loopthroughvalidationlist()
  Dim c As Range
  For Each c In Range(Range("A3").Validation.Formula1)
    MsgBox c.Value
  Next
End Sub
Hi and welcome to MrExcel.

How about:

VBA Code:
Sub loopthroughvalidationlist()
  Dim c As Range
  For Each c In Range(Range("A3").Validation.Formula1)
    MsgBox c.Value
  Next
End Sub
Works perfectly!! It does exactly what I needed. Thank you!
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,283
Members
449,075
Latest member
staticfluids

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