Run a macro with a variable


Posted by Edd P on March 09, 2001 4:29 AM

I am currently producing a sheet that will take a variable from a cell on the sheet. The next stage is to run a macro of the same name as the variable. I have no clue as to how this can be done. Any body know???

Posted by David Hawley on March 09, 2001 1:27 PM

Hi Edd P

Sub TryThis()
Dim MacroName as String
MacroName="MySub"
Run MySub
End Sub


Sub MySub
Msgbox "Hello"
End Sub

Dave
OzGrid Business Applications

Posted by Dave Hawley on March 09, 2001 1:29 PM

Oops Typo!

Sub TryThis()
Dim MacroName as String
MacroName="MySub"
Run MySub
End Sub

Sub MySub()
Msgbox "Hello"
End Sub


Dave
OzGrid Business Applications

Posted by Celia on March 09, 2001 2:39 PM

Re: Oops Typo!

Dave


Edd P
Dave pasted the same typo. Should be :-
Sub TryThis()
Dim MacroName as String
MacroName="MySub"
Run MacroName
End Sub

Sub MySub()
Msgbox "Hello"
End Sub

If you want to take the macro name from a worksheet cell (say,A1) :-
Sub TryThis()
Dim MacroName as String
MacroName=Range("A1")
Run MacroName
End Sub

Sub MySub()
Msgbox "Hello"
End Sub

Celia

Posted by Dave Hawley on March 09, 2001 2:59 PM

Help! I'm being stalked!

I actualy missed out the () in my first post, didn't even realise I had the other typo. That's what happen when you type directly at 0500 without testing I guess :)


DaveOzGrid Business Applications



Posted by Dave Hawley on March 09, 2001 3:00 PM

Help! I'm being stalked!

I actualy missed out the () in my first post, didn't even realise I had the other typo. That's what happens when you type directly at 0500 without testing I guess :)


DaveOzGrid Business Applications