Worksheet navigation [between split parts]

I am new to LibreOffice and pleased to be here. I have converted all my O365 workbooks to LO and they do what I need however I am now tackling ‘housekeeping’ issues, one of which is sheet navigation. All my workbooks are multisheet, each wsheet uses a horizontally split screen and many have a vertical split too. The sheets are split at varying rows and columns. To navigate there are 4 self explanatory movements Goto_Top, Goto_Bottom, Go_Up and Go_Down for incremental moves. I link each function to a button. Currently the incremental moves are limited to the visiblerange but I may wish to move to the top of tables instead.

The code below works for Go_Up and Go_Down, but only if I select a cell below the frozen row.
My question is how do I select a cell in that visiblerange?

Please bear in mind I may want to begin navigation half way down my data and go either way.
I do not want to select a cell outside of the visiblerange as this would cause a secondary jump.
And once a cell is selected in the lower pane it should not be repeated as that again would cause unecessary secondary jumps and possible screen flicker.

Dim nVisibleRows As Long

Function Get_First_Visible_Row
	Dim oDoc: oDoc = ThisComponent
	Dim oCtrl As Object: oCtrl= oDoc.CurrentController
	Dim aVisibleRange As New com.sun.star.table.CellRangeAddress
	aVisibleRange = oCtrl.getVisibleRange()
	nVisibleRows = aVisibleRange.EndRow - aVisibleRange.StartRow + 1
	Get_First_Visible_Row = aVisibleRange.StartRow
End Function

Sub Scroll_Down()
	Dim oDoc As Object: oDoc = ThisComponent
	Dim oCtrl As Object: oCtrl = oDoc.CurrentController
	oCtrl.FirstVisibleRow = Get_First_Visible_Row + nVisibleRows
End Sub

Sub Scroll_Up()
	Dim oDoc As Object: oDoc = ThisComponent
	Dim oCtrl As Object: oCtrl = oDoc.CurrentController
	oCtrl.FirstVisibleRow = Get_First_Visible_Row - nVisibleRows
End Sub

(Hope that turns out as intended)
Yes, I know I can do all this manually with the slider bar but that’s not what I want to do and often the slider is so small as to be almost useless. I have extensively experimented to get the freezerow of any given sheet and to establish if there are panes and other methods but all to no avail. I would very much appreciate a solution or pointers from more experienced LO users. As an aside, this was all easy peasy after 40 years in VBA but I am now a totally committed LO user and enjoying the new experience so far.

Version: 25.2.5.2 (X86_64) / LibreOffice Community
Build ID: 03d19516eb2e1dd5d4ccd751a0d6f35f35e08022
CPU threads: 20; OS: Windows 11 X86_64 (10.0 build 26100); UI render: Skia/Vulkan; VCL: win
Locale: en-AU (en_AU); UI: en-GB
Calc: CL threaded

like what ? :thinking:

How to freeze columns and rows in multiple sheets - #2 by fpy

Strictly speaking, VBA appeared in 1993 (and I’ve known it since then). :slight_smile:
I think, colleague, it would be worthwhile to upload a file in .ods format with your macros and explain what causes problems and in what cases.
Perhaps you will be interested in this topic.

@fpy Thank you for your interest. It isn’t the setting of freeze rows per se, it is more about finding a method to get the row number of an existing freeze row with the idea of selecting a cell in the row below to get access to the lower pane. But I have read in AI generated code snippets there is no direct way of doing that in LO however I do not yet know if that statement is correct.
What I have found so far is that if I manually select a cell in the lower pane the visiblerange method works as desired but it would be great if I could do that initial, and once only selection, in a macro bearing in mind I want this navigation method to be available in all my wbooks.
I will prepare a sanitised ods as suggested by sokol92 to better show what I am trying to do.

@ sokol92. You are right, I was loose with my words. To be more accurate my first computer was a BBC2 ‘B’ marketed in 1982 and used a language called BBC Basic. A lot of water has gone under the bridge in those years since :grinning:
I will do as you suggest and prepare a sanitised wbook to better demonstrate my objective.

well, that was an entry point to discussions about the tricks to move in and around panes …

to get familiar with LO and use the turnkey solution → https://wiki.documentfoundation.org/Development/DispatchCommands

document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args(1) as new com.sun.star.beans.PropertyValue
args(0).Name = "By"
args(0).Value = 1
args(1).Name = "Sel"
args(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoDownBlock", "", 0, args())  '  resp. GoUpBlock

Recording a Macro

@sokol92
Here is a barebones ods. I have annotated the sheet as best I can. There are 2 versions of the incremental U and D buttons, v2 is the dispatcher suggestion from fpy and the buttons will need to be reassigned if you have the time and are inclined. It was very nearly the answer and so simple to implement but it failed twice when moving downwards as I explain on the wsheet.
It would be good to get the issue consistantly right.

Lotto System 8 - sanitised.ods (185.8 KB)

@fpy
Wow the dispatcher suggestion was very close to solving the issue and so easy to implement however the method failed twice by resetting its counter to zero when moving downwards as I explain in the stripped down ods I have just uploaded to sokol92.
Thank you both for the effort and time given so far.

@fpy Thank you.
After further testing I am marking the dispatcher method as a solution as I cannot replicate the row counter reset error I encountered initially. The remarkable thing about this method is that whilst it does not return a freezerow number, it physically places the cursor in the second pane regardless of how many rows are in the first pane and that is exactly what I asked for.
A simple, yet versatile and powerful method. Another reason to be happy I have migrated to LO.