Nicolai Lissau
Nicolai Lissau

Reputation: 8322

Using character as argument to function

I would like to be able to only pass q as argument to a function, so that the user does not have to enter a string "q".

I have a function defined in a module

Function doThis(val As Variant)

  MsgBox CStr(val)

  ' Here is a comparison of val with other strings and additional code

End

I call it from my worksheet:

=doThis(q)

And the messagebox returns

Error 2029

I have tried with String and Boolean as value type as well, but only variant fires the function.

Is it possible to receive a q as argument?

Upvotes: 0

Views: 922

Answers (1)

Gary's Student
Gary's Student

Reputation: 96771

Quite simple. First create a Defined Name for q

enter image description here

Secondly in a standard module:

Function doThis(val As Variant)
    MsgBox CStr(val)
    doThis = ""
End Function

Finally in the worksheet:

enter image description here

Upvotes: 2

Related Questions