Calling arbitrary procedures

beliblis

New Member
Joined
Nov 4, 2005
Messages
1
I would like to know how to call, from excel vba, an arbitrary procedure located in a module associated with a spreadsheet. Ideally it would work like this:
1) user enters a procedure name in a cell as plain text (eg, user enters "func_a" into cell A1)
2) some time later inside vba script, the value of this cell is read (some_variant = cells(1,1).value)
3) the script then executes a procedure named identical to the user's text (somehow call the function with the name identical to the string value of some_variant)

For the sake of simplicity, I will assume that the code for func_a is located in Module1 of the same workbook as the spreadsheet with [A1]="func_a". The point of this is that I do not want to limit the procedure names, so I cannot hard-code function calls based on the text. Code such as "if string="func_a" then call func_a" will not work, the user needs to be able to enter arbitrary procedure names. I have not been able to figure out how to do this with the vba "Call" statement, but maybe you can!

Thanks!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Welcome to MrExcel Board!

Perhaps something like this will work:

Code:
Dim mySub As Variant

    mySub = Worksheets("Sheet2").Range("A1").Value
    Application.Run mySub

Hope that helps!
 
Upvote 0

Forum statistics

Threads
1,215,619
Messages
6,125,873
Members
449,267
Latest member
ajaykosuri

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