VBA Loop Through Data Validation Drop Down List

RMBruno

New Member
Joined
Mar 18, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

I am new to macros and when I tried to record a macro of myself clicking through data validation list to update certain formulas, it seems as though the action would not be recorded.

I have a drop down list in cell "K3" that has 5 options which are linked to cells "A3:A7"

I also have a drop down list in cell "I58" that has 4 options linked to cells "A59:A62"

For each drop down in cell "K3", I need to loop through each drop down in "I58"..

For example, I set the first drop down in "K3", then I click through each option in "I58", then click the second dropdown in "K3" and repeat running through each dropdown in "58" and so on..

Can someone please help me out? Thank you so much in advance and let me know if I need to clarify anything!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
If the dropdown uses a list, and the list is in the range you specified, then you can just loop through that range to obtain the list.

VBA Code:
Sub demo1()
    Dim R As Range
    Dim VList As String

    For Each R In Range("A59:A62")                    'dropdown list for  cell I58
        VList = VList & R.Value & vbCr
    Next R

    MsgBox VList, , "Validation List for cell I58"
End Sub
 
Upvote 0
If the dropdown uses a list, and the list is in the range you specified, then you can just loop through that range to obtain the list.

VBA Code:
Sub demo1()
    Dim R As Range
    Dim VList As String

    For Each R In Range("A59:A62")                    'dropdown list for  cell I58
        VList = VList & R.Value & vbCr
    Next R

    MsgBox VList, , "Validation List for cell I58"
End Sub
Appreciate the reply. Will this code click through each option in the list for for cells I58 and K3?

Does not seem to be updating anything when I run this macro
 
Upvote 0
Appreciate the reply. Will this code click through each option in the list for for cells I58 and K3?

Does not seem to be updating anything when I run this macro

The word "click" implies some sort of keyboard or mouse interaction. The code does not do that. It will loop through the range of cells that store your validation list. In other words, it provides you with VBA access to the validation list. What you do with that is up to you. But the questions you are asking make me think that you are asking a completely different question.
 
Upvote 0
The word "click" implies some sort of keyboard or mouse interaction. The code does not do that. It will loop through the range of cells that store your validation list. In other words, it provides you with VBA access to the validation list. What you do with that is up to you. But the questions you are asking make me think that you are asking a completely different question.
Understood. I may be mistaken.

In order to update a model, I need to click through 3 different hold periods (which are the in the data validation list). Once I set that cell to 3 years, the model will update, then I click the data validation to set it to 5 years, so the model returns will update for that hold period and so on.

When I tried to simply record myself clicking through these options, it did not seem to follow. Maybe there is not a way to run this in a macro.

I appreciate your help
 
Upvote 0
It sounds like you need to be using the worksheet change event subroutine, which can be used to detect when you have changed the dropdown selection and then take some action that you define in VBA code.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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