LO Calc - how to select a range using lastfield and a named cell in BASIC

Folks:
I’ve spent hours researching this issue before posting here.

I’m trying to create a sort macro in BASIC. The script works when I specify the cells manually but data may be added to the sort range, so it must be able to determine the last row/column. The issue is when creating the sort range. I’ve used the function below to select all the data but the 1st two rows are headers, so I need to exclude them from the sort range.

Function getUsedRange(oSheet)
    Dim oCursor
    oCursor = oSheet.createCursor()
    oCursor.gotoStartOfUsedArea(False)
    oCursor.gotoEndOfUsedArea(True)
    getUsedRange = oCursor
End Function

How do I specify the 1st range as a named cell and replace the “oCursor.gotoStartOfUsedArea(False)” line?

Thanks

Peace and blessings,
JQ

Hallo
In case you know about how many rows to skip:

'#…'
    oCursor.gotoStartOfUsedArea(False)
    oCursor.gotoOffset(0, 2) '# exclude first two rows`
    oCursor.gotoEndOfUsedArea(True)

Hallo

doc = XSCRIPTCONTEXT.getDocument()
sheet = doc.getCurrentController().getActiveSheet()
named_ranges = doc.NamedRanges
start = named_ranges['starthere'].ReferredCells
cursor = sheet.createCursorByRange(start)
cursor.gotoEndOfUsedArea(True)

Except for the typo error, which I didn’t immediately catch, the “gotoOffset” function worked.

Thank you.

Peace and blessings,
JQ