Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default 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
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
What is calling this? Risky Dave Excel Programming 5 December 2nd 08 12:51 PM
VBA calling ppt Eddy Excel Programming 2 June 4th 07 12:36 PM
Need Help using/calling a DLL Trip[_3_] Excel Programming 1 January 9th 06 01:36 PM
Need Help Using/Calling DLL Please Trip[_3_] Excel Programming 0 January 8th 06 09:57 AM
Calling an Add-In BillCPA Excel Discussion (Misc queries) 2 August 11th 05 09:32 PM


All times are GMT +1. The time now is 06:38 PM.

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"