Passing Range Object to ExcelDna functions

Jun 26, 2012 at 10:49 PM

I want to pass Range; multiple values from Excel to Excel Dna UDF; how can I do this ?

 

Thanks

Coordinator
Jun 27, 2012 at 10:35 PM
Edited Jun 27, 2012 at 11:01 PM

Hi,

You can just define your function as taking an array. In C# it would look like this:

 

public static string MyFunction(object[,] inputValues)
{
    int rows = inputValues.GetLength(0); 
    int columns = inputValues.GetLength(1);
    for (int i = 0; i < rows; i++)
    {
        for (int j = 0; j < columns; j++)
        {
            object val = inputValues[i, j];
            // ... inputValues array will have strings, doubles, etc.
        }
    }
}

Then your formula can be something like:

=MyFunction(A1:B20)

and you'll get the right values in your function.

Regards,

Govert