not too hard VBA help PLEASE!

G

Guest

Guest
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!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,487
Messages
6,113,943
Members
448,534
Latest member
benefuexx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top