View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
T. Valko T. Valko is offline
external usenet poster
 
Posts: 15,768
Default Call a Visual Basic Function with VLookup

Clarification:

Are your variables arguments to the UDF as cell references? For example:
=FunctionA(do_something,A10,B10)
If so, you could use CHOOSE:


You can use CHOOSE *only* if your variables as cell references are already
defined in the UDF code.

--
Biff
Microsoft Excel MVP


"T. Valko" wrote in message
...
Are your variables arguments to the UDF as cell references? For example:

=FunctionA(do_something,A10,B10)

If so, you could use CHOOSE:

A1 = FunctionA
A2 = FunctionB

=CHOOSE(MATCH("FunctionB",A1:A2,0),FunctionA,Funct ionB)

In versions of Excel prior to Excel 2007 you'd be limited to 29 functions.


--
Biff
Microsoft Excel MVP


"ajd" wrote in message
...
I'll be running my functions on each cell in a vertical list of varying
length. So that's why I didn't want to have a macro, it'd be much easier
if
it was just a function or a call to a function. I know it's possible
with a
macro, just makes things more complicated since the users may not be
aware of
the macro and/or could forget to run it.

To clarify, the variables for the functions are the values in a separate,
unrelated cell say in Column A. The function, which I want to run in
Column
C, is determined by a value in say column B (via a table that I'm trying
to
access in a vlookup).

Also I would like to have the ability to have say 10 different functions
that I can choose from, depending on the value in Column B, which is why
I
wanted the vlookup instead of a very lengthy if clause.

So, here's what my table looks like:

VariableX Name Y Formula that runs proper function with
VariableX
VariableA Name Z Formula that runs proper function with
VariableA
etc

With another table that assigns the name to a function, with:
Name Z FunctionZ
Name Y FunctionY
etc



"Luke M" wrote:

Is there a way you could have a cell do the VLOOKUP, and then in VBA
write
something like

If Range("A1").value = "A" then
Function A
Else Runction B
End If

As for the variables, I'm not quite sure what you mean. Is the result of
the
vlookup the variable? If so, you could just refer to the cell value
mentioned
above.
--
Best Regards,

Luke M


"ajd" wrote:

I wrote a few functions in Visual Basic. I want to determine which
function
to run based on a vlookup of a list of the functions in a table. So I
have a
table that has:

A FunctionA
B FunctionB

I want to do a vlookup on A to run FunctionA, and also provide the
variable
for Function (which does not depend on the specific function to be
run). I
can't figure out a way for vlookup to not just return text, but return
a
function to run, and then also provide the variables for that function
to run
on.

Thanks.