ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Call a subroutine using variable subroutine name (https://www.excelbanter.com/excel-discussion-misc-queries/238026-call-subroutine-using-variable-subroutine-name.html)

dhstein

Call a subroutine using variable subroutine name
 
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.

Mike H

Call a subroutine using variable subroutine name
 
Try this

Application.Run Sheets("Sheet1").Range("A1").Text

Mike

"dhstein" wrote:

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.


Gary''s Student

Call a subroutine using variable subroutine name
 
For example:

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

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

--
Gary''s Student - gsnu200859


"dhstein" wrote:

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.


dhstein

Call a subroutine using variable subroutine name
 
Thanks Mike and Gary - that worked well.

David


"Mike H" wrote:

Try this

Application.Run Sheets("Sheet1").Range("A1").Text

Mike

"dhstein" wrote:

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.



All times are GMT +1. The time now is 03:01 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com