Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Calling a sub
Hi,
XL 2003 I'm trying to call a subroutine using a variable to name part of the subroutine, but I can't find a syntax that works. ie: I have several sorting Subs called SortByA, SortByB, SortByC etc Using an input box, the user is prompted to enter a letter, which I assign to the variable: 'answer' I then want to call one of the Subs, like this: Call "SortBy" & answer But the above syntax (and lots of others) were rejected. Can this be done? Regards - Dave. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Calling a sub
Dave;479036 Wrote: Hi, XL 2003 I'm trying to call a subroutine using a variable to name part of the subroutine, but I can't find a syntax that works. ie: I have several sorting Subs called SortByA, SortByB, SortByC etc Using an input box, the user is prompted to enter a letter, which I assign to the variable: 'answer' I then want to call one of the Subs, like this: Call "SortBy" & answer But the above syntax (and lots of others) were rejected. Can this be done? Regards - Dave. Hello Dave, You can do this using "Application.Run" Application.Run "SortBy" & Answer -- Leith Ross Sincerely, Leith Ross 'The Code Cage' (http://www.thecodecage.com/) ------------------------------------------------------------------------ Leith Ross's Profile: http://www.thecodecage.com/forumz/member.php?userid=75 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=132122 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Calling a sub
Before attempting to find an answer to your question, let's make sure you
are asking the right question. The naming system of your subroutines and the method you are using to identify them for execution leads me to believe each subroutine is the same (that is, same code structure) except for the column that will be processed. If that is the case, then you are approaching the problem incorrectly. If I am right, then what you should do is create a single subroutine with a String argument... pass the letter the user inputs as the argument when you call the subroutine and then let the subroutine use that column within the code. It is hard to give you more of an explanation than that without seeing the subroutine code you are calling. -- Rick (MVP - Excel) "Dave" wrote in message ... Hi, XL 2003 I'm trying to call a subroutine using a variable to name part of the subroutine, but I can't find a syntax that works. ie: I have several sorting Subs called SortByA, SortByB, SortByC etc Using an input box, the user is prompted to enter a letter, which I assign to the variable: 'answer' I then want to call one of the Subs, like this: Call "SortBy" & answer But the above syntax (and lots of others) were rejected. Can this be done? Regards - Dave. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Calling a sub
Hi Leith,
Thanks! I used to use 'Application.Run', but when I discovered 'Call' I just used that 'cause it was so much easier to type, and I thought it did the same thing. Not quite, evidently... Regards - Dave. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Calling a sub
Hi Rick,
You are right about that. I have done just as you say. But when I couldn't seem to use a variable to call a Sub, I became curious as to whether it was possible. Thanks for your input. Dave. "Rick Rothstein" wrote: Before attempting to find an answer to your question, let's make sure you are asking the right question. The naming system of your subroutines and the method you are using to identify them for execution leads me to believe each subroutine is the same (that is, same code structure) except for the column that will be processed. If that is the case, then you are approaching the problem incorrectly. If I am right, then what you should do is create a single subroutine with a String argument... pass the letter the user inputs as the argument when you call the subroutine and then let the subroutine use that column within the code. It is hard to give you more of an explanation than that without seeing the subroutine code you are calling. -- Rick (MVP - Excel) "Dave" wrote in message ... Hi, XL 2003 I'm trying to call a subroutine using a variable to name part of the subroutine, but I can't find a syntax that works. ie: I have several sorting Subs called SortByA, SortByB, SortByC etc Using an input box, the user is prompted to enter a letter, which I assign to the variable: 'answer' I then want to call one of the Subs, like this: Call "SortBy" & answer But the above syntax (and lots of others) were rejected. Can this be done? Regards - Dave. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
What is calling this? | Excel Programming | |||
VBA calling ppt | Excel Programming | |||
Need Help using/calling a DLL | Excel Programming | |||
Need Help Using/Calling DLL Please | Excel Programming | |||
Calling an Add-In | Excel Discussion (Misc queries) |