Call a subroutine using variable subroutine name

D

dhstein

If I have a cell with the contents of a subroutine name for example
A1 = "Mysub"

So if I do
Dim CodeToExecute As String
CodeToExecute = Range("A1").Value

I want to call Mysub using the variable CodeToExecute

Any help is appreciated.
 
G

Gary''s Student

For example:

Sub Mysub()
MsgBox ("HELLO")
End Sub

Sub dhstein()
Dim CodeToExecute As String
CodeToExecute = Range("A1").Value
Application.Run (CodeToExecute)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top