[Solved] Passing cell range as argument to user-defined macro function

2 replies [Last post]
allencch
Offline
Last seen: 1 year 35 weeks ago
Title:
Joined: 27 Mar 2013
Posts: 2

I would like to define my own macro function. When passing the argument, I would like to pass the range of cells. However, I cannot find any information about the datatype that will be passed from internet.
In Microsoft Office VBA, it can be done by

Function myFunc(r As Range)
    'Do something
    myFunc = result
End Function

Then in the cell, I can enter something like
=myFunc(A1:B2)
without quoting the argument as string.

In VBA, the datatype is declared as Range. I would like to know what is it in LibreOffice?

karolus
Offline
Last seen: 9 hours 17 min ago
Title: ★★★★★
Joined: 11 Mar 2012
Posts: 181
Hallo Its ugly to deal with

Hallo

Its ugly to deal with CellRangeArguments in UDFs but here we are:

function rangetest( inrange as variant )
rowcount = ubound(inrange, 1)
colcount = ubound(inrange, 2)
for row = 1 to rowcount
for col = 1 to colcount
print inrange( row, col)
next
next
end function

Karolus


allencch
Offline
Last seen: 1 year 35 weeks ago
Title:
Joined: 27 Mar 2013
Posts: 2
@karolus, really thanks. This

@karolus, really thanks. This is a great help. Other some testing through the debug, I also figure out it is Variant. But your code for the looping of two dimensional array using LBound and UBound is really help.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.