[Of course, I don’t need all the complexity, and I won’t study the contained code.]
Obviously my assumption concerning the order of the findings was wraon - and in hindsight I have to concede that I should have known.
I now suggest a similar but substantially different approach:
To get the bottommost “\S-cell” of the right most “\S-column” of a sheet, first look for the rightmost column wit \S-cells, and then pick the bottommost \S-cell of it. This should even be more efficient.
Raw code:
Sub reportLastUsedCellOfLastUsedColumnDisregardingWhitespace()
REM Formula cells are disregarded!
sheet = ThisComponent.CurrentController.ActiveSheet
cellCur = sheet.createCursor()
cellCur.gotoStartOfUsedArea(False)
cellCur.gotoEndOfUsedArea(True)
lmC = cellCur.RangeAddress.StartColumn
rmC = cellCur.RangeAddress.EndColumn
sd = sheet.createSearchDescriptor()
With sd
.SearchRegularExpression = True
.SearchString = "\S" REM One character not being of character type WhiteSpace
End With
bmormC = -2 REM Finally printing -1 if no \S cell was found in the sheet.
bmormR = -2
For c = rmc To lmC Step -1
c_Column = sheet.Columns(c)
findings = c_Column.findAll(sd)
uF = -1
If NOT IsNull(findings) Then
bmormC = c
uF = findings.Count - 1
EndIf
If uF>=0 Then
bmormR = findings(uF).RangeAddress.EndRow
Exit For REM Final result found
EndIf
Next c
MsgBox("R" & (bmormR + 1) & "C" & (bmormC + 1))
REM "R-1C-1" meaning "No \S cell found in the sheet".
End Sub