Two questions, can user-defined functions in libreoffice calc accept cross-sheet range as arguments?

and how to define function accept variable length arguments like `CHOOSE(i, n1, n2, ...)`

?

**cross-sheet range function**

I define a single argument function:

```
function CHOOSERANGE(n as long, range)
dim r
r = "#ERR:502"
dim i
i = 1
for each x in range
if i = n then
r = x
exit for
end if
i = i+1
next
' ReDim range(0 To size-1)
CHOOSERANGE = r
end function
```

Then I call it as `=CHOOSERANGE(1, sheet1.A1:sheet2.B2)`

,

but it return a 504 error code (Function parameter is not valid) .

Some function like SUM can accept cross-sheet range,

can we define these kind of functions with macro?

**Variable length arguments function**

I searched and get nothing about this topic.

I am very new to BASIC, maybe I used the wrong term.