not too hard VBA help PLEASE!
Upcoming Power Excel Seminars
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: not too hard VBA help PLEASE!

  1. #1
    Guest

    Default

     
    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. #2
    Board Regular
    Join Date
    Feb 2002
    Location
    Stockton, California
    Posts
    281
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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. #3
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    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

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com