| View previous topic :: View next topic |
| Author |
Message |
andrewl18 Newbie

Joined: 10 May 2012 Posts: 2
|
Posted: Thu May 10, 2012 7:49 am Post subject: Code to find the next empty row... |
|
|
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
Thanks! |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8984 Location: Lexinton, Kentucky, USA
|
Posted: Thu May 10, 2012 1:30 pm Post subject: |
|
|
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 |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8984 Location: Lexinton, Kentucky, USA
|
Posted: Thu May 10, 2012 1:49 pm Post subject: |
|
|
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 |
|
 |
andrewl18 Newbie

Joined: 10 May 2012 Posts: 2
|
Posted: Fri May 11, 2012 6:30 am Post subject: |
|
|
| Thanks very much! |
|
| Back to top |
|
 |
|