Page 1 of 1

Finding last used cell in a range

Posted: Fri Jun 30, 2017 10:36 am
by Fraz627
How would I go about finding the last cell with data in a range and or a rangename?

My searches have been in vain.

Thanks

Re: finding last used cell in a range

Posted: Fri Jun 30, 2017 10:49 am
by Villeroy

Code: Select all

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

Function getCurrentRegion(oRange)
REM rectangle of adjacent non-empty cells
Dim oCursor
	oCursor = oRange.getSpreadSheet.createCursorByRange(oRange)
	oCursor.collapseToCurrentRegion
	getCurrentRegion = oCursor
End Function

Function getMergedRegion(oRange):
REM Get merged range around given range.
Dim oCursor
    oCursor = oRange.getSpreadsheet().createCursorByRange(oRange)
    oCursor.collapseToMergedArea()
    getMergedRegion = oCursor
End Function

Function getCurrentArray(oCell)
REM area of current array formula
Dim oCursor
	oCursor = oCell.getSpreadSheet.createCursorByRange(oCell)
	oCursor.collapseToCurrentArray
	getCurrentArray = oCursor
End Function

Re: finding last used cell in a range

Posted: Fri Jun 30, 2017 11:39 am
by Fraz627
Thanks however I pretty new at this, I don't quite know how to go about using this.

thanks

Re: finding last used cell in a range

Posted: Fri Jun 30, 2017 11:41 am
by Villeroy
Learn how to program.

Re: finding last used cell in a range

Posted: Fri Jun 30, 2017 11:56 am
by Fraz627
Whie I'm new to Open office, been programing for years in VBA. I'm just trying to convert a few VBA macros to Open office. Its not easy (in my eyes) to understand, things that take a couple of lines in VBA take about twenty.
Thanks again for Your time.

Re: finding last used cell in a range

Posted: Fri Jun 30, 2017 12:21 pm
by RoryOF
Andrew Pitonyak's books are the bibles for OO Macro Programming, downloadable from
Andrew Pitonyak's macro books

Re: finding last used cell in a range

Posted: Fri Jun 30, 2017 1:58 pm
by Villeroy
Fraz627 wrote:Whie I'm new to Open office, been programing for years in VBA.
Then you should know what a function does.
This is not VBA, not even close. The open source application provides very abstract, bare bone programming interfaces. There is almost no sugar coating but free choice between several programming languages.
This whole office suite is about as large as the VBA components in MS Office alone.