Run macros from drop down list

kbattiola

New Member
Joined
Sep 29, 2011
Messages
1
I have built a series of macros and want to be able to select from them in a drop down list. I can use a list or combo box to create the drop down list, but I am unsure how to write VBA to read the text and run the correlating macro (name of macro is identical to text shown in drop down list). Can someone provide me step by step basic instructions on how I can do this?

If this isn't possible, I would have to create a button for each of my 12 macros. How do I assign a macro to a button?

Much appreciated!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I don't have an answer to your first question, but if you create a form button (not a control button) you can just right click on it, assign macro, then select the macro.
 
Upvote 0
Welcome to MrExcel.

Say you use Data Validation for your dropdown in A1. Right click the sheet tab and choose View Code. Paste this into the window on the right:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address <> "$A$1" Then Exit Sub
    Application.Run Target.Value
End Sub

Change the reference to A1 to suit (but make sure the $ signs remain). The macro will fire automatically when you select from the dropdown.
 
Upvote 0
Welcome to the board!

While you can create such listbox, is there any particular reason to not use Excel's built in shortcut ALT + F8 which shows all (public) macros?

To use listbox you will have to put all macros in Module and then run them by using following basic syntax like:
Code:
Dim sMacro as String
sMacro = "Module1." & Listbox1.value
Application.Run sMacro
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,292
Members
452,902
Latest member
Knuddeluff

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