OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Code to find the next empty row...

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base
View previous topic :: View next topic  
Author Message
andrewl18
Newbie
Newbie


Joined: 10 May 2012
Posts: 2

PostPosted: Thu May 10, 2012 7:49 am    Post subject: Code to find the next empty row... Reply with quote

Can someone help me with some code in BASIC to find the next empty row in a spreadsheet starting from cell B7, and then paste information into that row?

I've done the copying of the information and going to the required sheet, but can't figure out the empty row bit Sad

Thanks!
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Thu May 10, 2012 1:30 pm    Post subject: Reply with quote

This macro will find the last used row used, move down 1 and print something in the first 6 columns of that row.
Code:
Sub Main
oSheet = ThisComponent.Sheets(0)
cur = oSheet.createCursor
cur.gotoEndOfUsedArea(false)
cur.gotoOffset(0 - cur.rangeAddress.endColumn,1)'Column A, Row end of use area +1
oCell = oSheet.getCellRangeByName(cur.AbsoluteName)
For c = 0 to 5 '5 is columns in row - 1
oCell = oSheet.getCellByPosition(c,oCell.RangeAddress.endRow)
cur = oCell.createTextCursor
cur.String = "New" & c
Next
End Sub
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Thu May 10, 2012 1:49 pm    Post subject: Reply with quote

Looking at your post again it appears that you want to paste in this "new" row and I have assumed you want to start your paste in column A. Here's the code that will prepare you for the paste.

Code:
Sub Main
oSheet = ThisComponent.Sheets(0)
cur = oSheet.createCursor
cur.gotoEndOfUsedArea(false)
cur.gotoOffset(0 - cur.rangeAddress.endColumn,1)'Column A, Row end of use area +1
oCell = oSheet.getCellRangeByName(cur.AbsoluteName)
ThisComponent.CurrentController.Select(oCell)
'Your paste routine goes here.
End Sub
Back to top
View user's profile Send private message
andrewl18
Newbie
Newbie


Joined: 10 May 2012
Posts: 2

PostPosted: Fri May 11, 2012 6:30 am    Post subject: Reply with quote

Thanks very much!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group