Finding last used cell in a range

Creating a macro - Writing a Script - Using the API

Finding last used cell in a range

Postby Fraz627 » Fri Jun 30, 2017 10:36 am

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
Fraz627
 
Posts: 15
Joined: Sat Jun 17, 2017 8:31 am

Re: finding last used cell in a range

Postby Villeroy » Fri Jun 30, 2017 10:49 am

Code: Select all   Expand viewCollapse view
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 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24085
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: finding last used cell in a range

Postby Fraz627 » Fri Jun 30, 2017 11:39 am

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
Fraz627
 
Posts: 15
Joined: Sat Jun 17, 2017 8:31 am

Re: finding last used cell in a range

Postby Villeroy » Fri Jun 30, 2017 11:41 am

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 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24085
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: finding last used cell in a range

Postby Fraz627 » Fri Jun 30, 2017 11:56 am

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
Fraz627
 
Posts: 15
Joined: Sat Jun 17, 2017 8:31 am

Re: finding last used cell in a range

Postby RoryOF » Fri Jun 30, 2017 12:21 pm

Andrew Pitonyak's books are the bibles for OO Macro Programming, downloadable from
Andrew Pitonyak's macro books
Apache OpenOffice 4.1.3 on Xubuntu 16.04 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 24745
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: finding last used cell in a range

Postby Villeroy » Fri Jun 30, 2017 1:58 pm

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 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24085
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 10 guests