[Solved] LASTROW function

Discuss the spreadsheet application
Post Reply
jess66
Posts: 3
Joined: Sat Jan 12, 2008 4:44 am

[Solved] LASTROW function

Post by jess66 »

I'm a newbie to OpenOffice. Some of my MS Office files use a LASTROW function that picks a value from the last row with entries on a spreadsheet. Is there a LASTROW function available for OpenOffice?
Last edited by jess66 on Sun Jan 13, 2008 4:50 am, edited 2 times in total.
TerryE
Volunteer
Posts: 1402
Joined: Sat Oct 06, 2007 10:13 pm
Location: UK

Re: LASTROW function

Post by TerryE »

Neither Excel nor Calc have a LASTROW function. In both you can write a Custom Basic function to return this for you.
Ubuntu 11.04-x64 + LibreOffice 3 and MS free except the boss's Notebook which runs XP + OOo 3.3.
User avatar
kingfisher
Volunteer
Posts: 2123
Joined: Tue Nov 20, 2007 10:53 am

Re: LASTROW function

Post by kingfisher »

If you have data arranged by row chronologically with the dates in one column, you could use VLOOKUP in conjunction with MAX or DMAX.
Apache OpenOffice 4.1.9 on Linux
User avatar
probe1
Volunteer
Posts: 277
Joined: Mon Oct 08, 2007 1:34 am
Location: Chonburi Thailand

Re: LASTROW function

Post by probe1 »

this one is take from colorRows

Code: Select all

'...
oDoc = ThisComponent
'...
actSheet = oDoc.currentController.ActiveSheet
vLastPos = FUNC_LastUsedCell(actSheet)
lRows = vLastPos(0)
' ...

' and the funtion used
' -------------------------------------------------------------------
' function uses variant array to return more than one value
Function FUNC_LastUsedCell(oSheet as Object) as Variant

oCursor = oSheet.createCursor()

oCursor.gotoEndOfUsedArea(TRUE) 
oEndAdr = oCursor.getRangeAddress

Dim vLastUsedCell(1) as Variant
vLastUsedCell(0) = oEndAdr.EndRow
vLastUsedCell(1) = oEndAdr.EndColumn 
FUNC_LastUsedCell = vLastUsedCell()

End Function
Does this help?

[posting from vacation: 8°52'55"N 98°16'1" E; actually 29°C]
Cheers
Winfried

DateTime2 extension: insert date, time or timestamp, formatted to your needs
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: LASTROW function

Post by Villeroy »

Apply a userdefined style to a whole column and the used area reaches to the bottom of the sheet.
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
jess66
Posts: 3
Joined: Sat Jan 12, 2008 4:44 am

Re: LASTROW function

Post by jess66 »

Since I already have a LASTROW function in XL, (part of a Morefunc add-on), my question should have been: How do I make this add-on accessible to Calc?
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: LASTROW function

Post by Villeroy »

Addons use special "communication channels" to interact with the application they are written for. The code assumes that it is integrated into a particular application to communicate with. It is technically impossible to use add-ons with a third party application.
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
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: LASTROW function

Post by JohnV »

Here's my effort to return the value of some cell in the last row. You must define the value of the col variable.

Code: Select all

sub LastRowContentOfSomeCell
dim document   as object,col
col = 0 'Columns are counted from 0 so this is column A.
dim dispatcher as object
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Sel"
args1(0).Value = false
dispatcher.executeDispatch(document, ".uno:GoToEndOfData", "", 0, args1())
Dim oCell,oSheet,targetCell
oCell = ThisComponent.CurrentSelection
oSheet = ThisComponent.Sheets.getByIndex(oCell.CellAddress.Sheet)
targetCell = oSheet.getCellByPosition(col,oCell.CellAddress.Row)
MsgBox targetCell.String
end sub
User avatar
probe1
Volunteer
Posts: 277
Joined: Mon Oct 08, 2007 1:34 am
Location: Chonburi Thailand

Re: LASTROW function

Post by probe1 »

Villeroy wrote:Apply a userdefined style to a whole column and the used area reaches to the bottom of the sheet.
No, it does not***

Apply a user defined formular to a column will do - but that was not the question, was it?

***[tested with OOo 2.1 on Suse 9.3 here - still on holidays with an "old" notebook]
Cheers
Winfried

DateTime2 extension: insert date, time or timestamp, formatted to your needs
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: LASTROW function

Post by Villeroy »

Sorry, whole column does not hold true, but have a look at the attachment (contains macro, push hyperlink @A1)
Attachments
UsedRange.ods
Used range set by formatting only
(15.11 KiB) Downloaded 736 times
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
jess66
Posts: 3
Joined: Sat Jan 12, 2008 4:44 am

Re: LASTROW function

Post by jess66 »

I've found the VLOOKUP function works for me. The first column is a continuous ascending date with entries almost every day, so the following works even if the date is off a day or two from TODAY.

Thanks for the help

VLOOKUP(TODAY();array;index)
Post Reply