NB This question refers to some features like optional LAMBDA arguments and the ISOMITTED function which are only available (at the time of writing) in the Beta channel (more info here)
I am trying to mimic VBA's paramarray in an Excel LAMBDA function, so would like a function:
=ARRAY(arg_1, [arg_2], [arg_3], ...)
...which returns the array {arg_1, arg_2, arg_3, ...}
dynamically sized according to however many args were passed.
If I know the number of args, I can just use the choose function like this:
=CHOOSE(SEQUENCE(number_of_args), arg_1, arg_2, arg_3, ...))
But I don't want to pass the number of arguments as a parameter, I want that to be dynamic. One idea was to do a binary search with ISOMITTED(arg_n)
to find the first missing argument. But that still hardcodes an upper limit on number of args to my ARRAY function, not to mention creating a nasty binary tree hardcoded.
This is of course easy with vba:
Public Function ARRAYFROMARGS(ParamArray args()) As Variant
ARRAYFROMARGS = args
End Function
Although this can only accept values which can be coerced into Variants so not lambdas or linked data types for example. This makes the non-VBA version more flexible.