Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 266
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default 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.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default 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.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 266
Default 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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stopping a userform subroutine teepee[_3_] Excel Discussion (Misc queries) 5 January 13th 09 01:10 AM
halt a subroutine question teepee[_3_] Excel Discussion (Misc queries) 3 December 28th 08 09:23 PM
SUBROUTINE HELP biker man Excel Discussion (Misc queries) 1 July 28th 07 04:06 PM
How to use this subroutine on multiple cells? Big Ian Excel Worksheet Functions 4 February 14th 06 02:01 PM
How do I exit a macro subroutine? John Excel Worksheet Functions 1 January 15th 06 02:08 AM


All times are GMT +1. The time now is 05:07 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"