Finding last used cell in a range

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Fraz627
Posts: 22
Joined: Sat Jun 17, 2017 8:31 am

Finding last used cell in a range

Post 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
Open Office 4.1 on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: finding last used cell in a range

Post 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
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Fraz627
Posts: 22
Joined: Sat Jun 17, 2017 8:31 am

Re: finding last used cell in a range

Post by Fraz627 »

Thanks however I pretty new at this, I don't quite know how to go about using this.

thanks
Open Office 4.1 on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: finding last used cell in a range

Post by Villeroy »

Learn how to program.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Fraz627
Posts: 22
Joined: Sat Jun 17, 2017 8:31 am

Re: finding last used cell in a range

Post 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.
Open Office 4.1 on Windows 10
User avatar
RoryOF
Moderator
Posts: 34613
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: finding last used cell in a range

Post by RoryOF »

Andrew Pitonyak's books are the bibles for OO Macro Programming, downloadable from
Andrew Pitonyak's macro books
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: finding last used cell in a range

Post 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.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply