Calling a sub

D

Dave

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.
 
R

Rick Rothstein

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.
 
D

Dave

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.
 
D

Dave

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top