How to return a matrix in a libre office calc basic function?

88 Views Asked by At

To enter a function that returns a matrix, I know I have to select all the cells for the returning variant and press CTRL SHIFT ENTER. The function can be defined as this minimal example:

Function test() as Variant
    dim res(1)
    res(0) = "test 0"
    res(1) = "test 1"
    test = res
end function

Then in the cell itself: {=test()}.

But it does not work. I have also tested test() = res().

Result is test 0 in both cells.

1

There are 1 best solutions below

0
BigBen On BEST ANSWER

I can't test either of these at the moment, but either TRANSPOSE when calling from the worksheet cell:

=TRANSPOSE(test())

or try using a 2D array:

Function test() as Variant
    dim res(0 to 1, 0 to 0)
    res(0, 0) = "test 0"
    res(1, 0) = "test 1"
    test = res
end function