functions; passing parameters; optional as string or range?

  • Thread starter Thread starter cate
  • Start date Start date
C

cate

I have a function
function saythis (message as string)

In the cell I would like to give the option to pass either a range
object (as cell address of another containing a string of text), or a
string, the message itself. Is it possible to do this?

I used (message as Variant) and can enter either into the function
call made in the cell, but I'm not sure what to do next.

Is there a typeof operator in VBA? I couldn't find one. How do you
tell what is passed in? How do you go about deciding if you have a
range object or a string? Can this even be done"

Thank you
 
The function TypeName will return the string "Range" for a range and
"String" for a string...

Select Case TypeName(Message)
Case "Range"
Case "String"
End Select

There is also a function VarType but it will return the type contained in
the range instead of the type range so that's why you need to use TypeName
instead...
 
Back
Top