Ruy
Ruy

Reputation: 569

How to get the row and column number of a cell using a LibreOffice Basic function

I would like to write a Libreoffice-Basic function that takes into account the row and column of the cell where the function is placed. I suppose my problem would be solved if I could define a function such as:

Function MyRowFun()
    MyRowFun = ?????
End Function

replicating the built-in function ROW(). In other words, once I typed "=MyRowFun()" in any given cell, that cell would display the same as if I had typed "=ROW()".

It would also be nice to be able to get the corresponding sheet name.

Thanks very much for any help, such as pointers to online manuals.


PS: After spending a lot of time searching, I have found many places explaining how to identify the cell under the selection, using ThisComponent.CurrentSelection.AbsoluteName, but I care about the cell where the formula is placed, rather than the currently selected cell.

Upvotes: 0

Views: 4313

Answers (2)

eeigor
eeigor

Reputation: 1

No SHEET(), ROW(), COLUMN()

Use Excel VBA Range. Just referring to itself. And without quotes.

C5: =UDF(Arg1;Agr2;C5)
________________________

Option VBASupport 1

Function UDF(Arg1, Arg2, Optional Caller)

    If Not IsMissing(Caller) Then

        sCallerName = Caller.CellRange.AbsoluteName

        Print sCallerName

    End If

End Function

Upvotes: 0

Jim K
Jim K

Reputation: 13819

For anyone else who comes across this question, the solution is given in the first comment by @JohnSUN:

If you know that SHEET(), ROW() and COLUMN() without parameters can return sheet-row-column numbers, then just pass them as parameters when calling your UDF.

The poster was hoping for a different type of solution but there isn't any other way.

Upvotes: 3

Related Questions