Try a second time.
Should work with 2 and 4 panes.
Comments are accepted.
Option Explicit
Global aInfo ' An array to store information about sheet panes.
' Element is an array of 10 elements. Indexes:
' 0: RuntimeUID of the document;
' 1: sheet index;
' 2-9: column and row of the active cell at the time the macro is called for panes 0-3
Global indInfo As Long
Global iCurrInfo As Long
' lang:en
' Remembers the active cell and moves to the next window pane.
' If possible, the previously saved cell for the target pane is set as active.
' - oDoc Spreadsheet document. If is missing then ThisComponent.
Sub JumpToNextPane(Optional ByVal oDoc As Object)
Dim oCont As Object
Dim nPanes As Long, currPane as Long, nextPane as Long, arr, arr2, aSh, i As Long
Dim iSheet As Long, shInfo As String, nCol as Long, nRow as Long, sep As String, vRange
If IsMissing(oDoc) Then oDoc=ThisComponent
If Not HasUnoInterfaces(oDoc, "com.sun.star.sheet.XSpreadsheetDocument") Then Exit Sub
oCont=oDoc.CurrentController
If Not HasUnoInterfaces(oCont, "com.sun.star.sheet.XSpreadsheetView") Then Exit Sub
nPanes=oCont.Count ' Number of Panes
If nPanes<2 Then Exit Sub
arr=Split(oCont.ViewData, ";") ' View Data: https://docs.libreoffice.org/sc/html/classScViewData.html#abb5889c04d6857f169f07e4fc15c03b8
iSheet=Clng(arr(1)) + 3 ' Active sheet index in arr
shInfo=arr(iSheet) ' Sheet info
sep="+" ' Token separator: + or /
arr2=Split(shInfo, sep)
If Ubound(arr2)=0 Then
sep="/"
arr2=Split(shInfo, sep)
End If
currPane=Clng(arr2(6))
If nPanes=4 Then ' Hori and Vert Split
nextPane=(Clng(arr2(6))+1) Mod 4
ElseIf arr2(2)="1" Then ' Vert
nextPane=IIf(currPane=2, 3, 2)
Else ' Hori
nextPane=IIf(currPane=2, 0, 2)
End If
arr2(6)=Cstr(nextPane)
' Look for information about the sheet in the aInfo array
FindInfoIndex oDoc.RuntimeUID, Clng(arr(1))
aSh=aInfo(indInfo)
' Save currpane
ash(2+2*currPane)=Clng(arr2(0))
ash(3+2*currPane)=Clng(arr2(1))
nCol=-1
If Not IsEmpty(ash(2+2*nextPane)) Then
nCol=ash(2+2*nextPane)
nRow=ash(3+2*nextPane)
End If
' pane index in controller numbering.
If nPanes=4 Then
i=IIf(nextPane=1, 2, Iif(nextPane=2, 1, nextPane))
Else
i=IIf(nextPane<currPane, 0, 1)
End If
' Check VisibleRange
vRange=oCont.getByIndex(i).VisibleRange
With vRange
If nCol>=0 Then
If nCol > .EndColumn Or nCol < .StartColumn Or nRow < .StartRow Or nRow > .EndRow Then nCol=-1
End With
If ncol=-1 Then
nCol=.StartColumn
nRow=.StartRow
End If
End With
arr2(0)=Cstr(nCol)
arr2(1)=Cstr(nRow)
arr(iSheet)=Join(arr2, sep)
oCont.restoreViewData Join(arr, ";")
End Sub
' Look for information about the sheet in the aInfo array.
' Assigns the iCurrInfo variable.
Sub FindInfoIndex(ByVal UID As String, ByVal n As Long)
Dim aSh, i As Long
If Not IsArray(aInfo) Then
ReDim aInfo(99)
indInfo=-1
iCurrInfo=-1
End If
If iCurrInfo>=0 Then
aSh=aInfo(iCurrInfo)
If aSh(0)=UID And aSh(1)=n Then Exit Sub
End If
For i=0 To indInfo
aSh=aInfo(i)
If aSh(0)=UID And aSh(1)=n Then
iCurrInfo=i
Exit Sub
End If
Next i
indInfo=indInfo+1
If indInfo>Ubound(aInfo) Then
ReDim Preserve aInfo(2 * Ubound(aInfo))
End If
aSh=DimArray(9)
aSh(0)=UID
aSh(1)=n
aInfo(indInfo)=aSh
iCurrInfo=indInfo
End Sub