Ask Your Question

In Libre Office Basic Macros, is there an equivalent function to the spreadsheet function column()?

asked 2016-12-27 04:05:47 +0200

oldgoatroper gravatar image

updated 2016-12-27 04:06:31 +0200

In Libre Office Basic Macros, is there an equivalent function to the spreadsheet function column()?

I've been looking around all day using google, but all I can find are very complex multi-line "solutions" that sometimes I'm not even sure what they are solutions for.

Anyway... returning the column of the current cell has to be something very basic and common that I'm figuring there must be some function call in LO Basic already that returns this in a very straightforward manner.

My macro needs to make a decision based on the column of the currently-selected cell

Something like:

Do While column() = 3




(and BTW, the Captcha at the bottom keeps showing up in a different language)

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2016-12-27 08:29:22 +0200

pierre-yves samyn gravatar image


Use currentselection to get... current selection, then CellAddress.column. It is however prudent to check that the selection is a cell. To do this, uncomment the lines in the code below:

dim oCell as object
oCell = thiscomponent.currentselection

'if oCell.supportsService("") then'
    msgbox oCell.CellAddress.column
'   msgbox "current selection is not a cell"    '
'end if '


edit flag offensive delete link more


Please also note that cell and range addresses start numbering with 0.

Lupp gravatar imageLupp ( 2016-12-27 13:52:54 +0200 )edit

answered 2016-12-27 17:53:29 +0200

oldgoatroper gravatar image

Thank you very much for this. It works just as I needed it to.

I was able to make my own function with your code, but I never would have been able to do it from scratch myself. For instance, oCell.supportsService("") would have never occured to me and I don't think I even stumbled across any reference to such in my search yesterday.

If there is a good reference listing and explaining the structure of properties of these objects, I would sure love to know about it.

Thanks, again... and yes, Lupp, I was aware of that.

edit flag offensive delete link more


Thank you for feedback.

My main source of documentation is IDL Reference. I also recommand Andrew Pitonyak and use of MRI extension as described here.

pierre-yves samyn gravatar imagepierre-yves samyn ( 2016-12-27 18:53:29 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-12-27 04:05:47 +0200

Seen: 555 times

Last updated: Dec 27 '16