1

Is it possible to invoke a function by specifying what the named parameters should be?

So for example if you have

Public function tmp(optional Byref a as integer=2, optional Byref b as integer=10)

    Tmp=a*b

End function 

I want to use the above by tmp(b=5). Hope someone can help.

3
  • 1
    Try: tmp(b:=5) Commented May 27, 2019 at 19:46
  • It works if the function is invoked from another function or sub. But is it possible to do same when the function I called from a cell? Commented May 27, 2019 at 19:55
  • 2
    you will call it the same way as described by T.M., One or both of your arguments will be a cell reference. example: in cell B2, put =tmp(,A2). If A2 value is 76, then the answer in B2 will be 152. And your arguments should be ByVal. Commented May 27, 2019 at 20:03

1 Answer 1

1

If I understand your question correctly, you want to pass only Argument b:

Debug.Print tmp(, 5)     ' results in 2 * 5 = 10

or simply as mentioned in comment by @Guest

Debug.Print tmp(b:=5)
Sign up to request clarification or add additional context in comments.

3 Comments

also this: Debug.Print tmp(b:=5)
Thanks for replying. But is it possible to do the same when the function is called from a cell? Your first suggestion I simple enough, when the numbers of parameters is limited, but as the complexity of the function grows, it will quickly become a headache.
You are welcome. - As to your question: you could pass a range argument with 2 columns defining only one or a few variables in the first column and the wanted values in the second one. To get further ideas you would need to define how you want to configure your function - could be worth to pose a new question with some more details :-) @RasmusAndersen

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.