![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
Can someone help me with the following code. This was posted by someone on this board to help me find the "last row (whatever it would be on a given day" for a cut and paste macro. Only trouble is, I get error messages on 3 different lines of it.
Any suggestions??? Sub FindLastRow() If WorksheetFunction.CountA(Cells)>0 Then 'Search for any entry, by searching backwards by Rows. lastrow=Cells.Find(What:="*",After:=[A1],_ SearchOrder:=xlByRows SearchDirection:=xlPrevious).Row End If EndofList=lastrow Range("A1").Select ActiveCell.Offset(EndofList,1).Range("A1").Select End Sub It definitely doesn't like the underscores, nor the "Search for any entry" line. Can anyone help with this? Thanks very much! |
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
|
It seems that this line of code should all be ONE line. Instead of:
lastrow=Cells.Find(What:="*",After:=[A1],_ SearchOrder:=xlByRows SearchDirection:=xlPrevious).Row it should be: lastrow=Cells.Find(What:="*",After:=[A1],SearchOrder:=xlByRows,SearchDirection:=xlPrevious).Row (This should be one line, it may not display that way because it wont fit on this webpage as one line) You may have got something wrong when you copied it. A SPACE then an UNDERSCORE lets you put code onto a next line to make it easier to read. Its like a continue mark, but you HAVE to put the space before the underscore. so the above line of could would be put in as: lastrow=Cells.Find(What:="*",After:=[A1], _ SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious).Row Hope that helps [ This Message was edited by: robfo0 on 2002-03-13 21:18 ] |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Try
Sub FindLastRow() If WorksheetFunction.CountA(Cells) > 0 Then 'Search for any entry, by searching backwards by Rows. lastrow = Cells.Find(What:="*", After:=[A1], _ SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious).Row End If EndofList = lastrow Range("A1").Select ActiveCell.Offset(EndofList, 1).Range("A1").Select End Sub Ivan |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|