I’m using Excel VBA to a write a UDF. I would like to overload my own UDF with a couple of different versions so that different arguments will call different functions.
As VBA doesn’t seem to support this, could anyone suggest a good, non-messy way of achieving the same goal? Should I be using Optional arguments or is there a better way?
Declare your arguments as
Optional Variants, then you can test to see if they’re missing usingIsMissing()or check their type usingTypeName(), as shown in the following example:This can be called from a worksheet as =FOO(), =FOO(number), or =FOO(‘string‘).