--------------------------------------------------
Excel-DNA is now registered on
GitHub Sponsors.
Please sign up for a monthly contribution to encourage support and development.
--------------------------------------------------
Hi Steven,
Most of the built-in Excel functions have been modified to understand array inputs, but this is not the default behaviour.
In particular, Excel will not do the array expansion for UDF functions unless they are explicitly implemented as array-aware.
Basically, you need to make the UDF take an 'object' argument, inspect whether it is a single value or an array, and return results based on the input shape.
I have made a small experiment that provides a function to do the above, to map a function taking a single value into an array-understanding function.
With this add-in installed, you can test this as
=ARRAY.MAP(AddOne, A1#)
(Note no quotes around the AddOne here - that gives the RegisterId for the function, which the ARRAY.MAP implementation understands).
In addition, you can pull the array-map functionality into your own function to make it array aware.
Suppose you rename your function to "AddOneImpl" (and possibly mark it as IsHidden=true)
Then you can do the ARRAY.MAP call like this
static object AddOne(object input) => XlCall.Excel(XlCall.xlUDF, "ARRAY.MAP", "AddOneImpl", input);
The ARRAY.MAP function allows functions to take many arguments, and one of these can be a 2D array, or two of the arguments can be 1D arrays.
So a function taking many parameters can work well in a table with row and column headers, returning s single 2D array as result.
-Govert