Search code examples
excel-dna

Excel DNA attempting to write array from UDF only writes single value


I am attempting to write either an array function or a dynamic array to Excel via a UDF written in Excel DNA (v.0.34). My result is always a single value instead of the array. What am I doing wrong?

    [ExcelFunction(Name = "WriteTestArray")]
    public static object[,] WriteTestArray()
    {

        try
        {
            return new object[2, 2] { { "one", "two" }, { "three", "four" } };
        }
        catch
        {
            return new object[,] { { ExcelError.ExcelErrorValue } };
        }
    }

Solution

  • For array functions to work with Excel (before the 'dynamic array' support that comes one day in a future version) you need to select the target range, then type in your formula and press Ctrl+Shift+Enter to commit it as an array formula. It will be indicated by curly brackets when displayed - e.g. {=MyFunc(...)}