Return to index: [Subject] [Thread] [Date] [Author]

Return and array from VBA to Excel

[Subject Prev][Subject Next][Thread Prev][Thread Next]

I am trying to get VBA for Excel 2003 to return an array from a custom function to a worksheet.  Following is some useless sample code.  Does anyone know how to get the array out of VBA and into a worksheet?


VBA Code:


Function array_test(n_rows, n_cols)

Dim array_data As Variant

    For i = 1 To n_rows

        For j = 1 To n_cols

            array_data(i, j) = i + j / 100

            Next j

        Next i

    array_test = array_data

End Function



Then I enter enter {=array_test(5,5)} in cell A1 and get “#VALUE!”.  Any suggestions would be appreciated.


Jake Watson, P.E.

Salt Lake City, UT