Ask Your Question
1

How can I extract row and column position of currently selected cell? [closed]

asked 2014-12-13 22:13:08 +0200

rezystorek gravatar image

updated 2014-12-13 22:27:19 +0200

I want to add to my workout spreadsheet helpful info in the frozen pannel on top of the screen (it calculates how much of specific workout I have to do today) and this information varies depending on row (as on different days I have different workout set which chooses 3 out of 9 exercises). My current solution are added additional columns which display that info for each row, but I have to scroll a lot every time I want to see it and it would be much better if it was sticked to the top (as my column labels are).

So I ask if there is a way to retrieve ROW and COLUMN (for meta computing adresses) of currently selected cell with a "cursor" - selector.

I haven't found anyone with such problem while googling.

You may better understand the problem if you look at my spreadsheet (warning: it's in polish). I want to delete the "Próg" columns and add displaying one row of the same data on the top (of frozen overlap) and make it change displaying info depending on current cursor (row) position. TEMPLATE.ods

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2016-03-07 01:51:09.316950

1 Answer

Sort by » oldest newest most voted
0

answered 2014-12-14 01:42:02 +0200

Lupp gravatar image

I sometimes (very rarely) use:

Function CurrentColumn() As Long
Dim ODoc As Object
Dim OSel As Object
oDoc = ThisComponent
oSel = oDoc.GetCurrentSelection()
If Not oSel.supportsService("com.sun.star.sheet.SheetCellRange") Then Exit Function
If (oSel.Columns().Count() > 1) Then Exit Function
CurrentColumn = oSel.CellAddress.Column()+1
End Function

Function CurrentRow() As Long
Dim ODoc As Object
Dim OSel As Object
oDoc = ThisComponent
oSel = oDoc.GetCurrentSelection()
If Not oSel.supportsService("com.sun.star.sheet.SheetCellRange") Then Exit Function
If (oSel.Rows().Count() > 1) Then Exit Function
CurrentRow = oSel.CellAddress.Row()+1
End Function

These functions, of course may be called by subs. I personally use them in cell formulae like

=CURRENTCOLUMN()+NOW()*0    or
=COMPLEX(CURRENTCOLUMN()+NOW()*0;CURRENTROW())

(Recalculation must be triggered one way or another for working.)

You may also learn about this subject studying this thread in another forum, in specific from an example, mariosv linked in from a Spanish forum.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-12-13 22:13:08 +0200

Seen: 2,643 times

Last updated: Dec 14 '14