+ Reply to Thread
Results 1 to 6 of 6

Excel can't find last row of data

Hybrid View

  1. #1
    Registered User
    Join Date
    08-24-2007
    Posts
    16

    Excel can't find last row of data

    Good afternoon, I am having an issue where excel is not going to the last row of data. The code line I am using is the following.

    ActiveCell.SpecialCells(xlLastCell).Select
               lrow = ActiveCell.Row
               Lcol = ActiveCell.Column
    
    Range("AJ2:BS2").Select
        Selection.Copy
        Range("AJ3").Select
        Range("AJ3:AJ" & lrow).Select
        ActiveSheet.Paste
        Application.CutCopyMode = False
    What happens is when it looks for the last row of data it goes 3 or 4 rows past the last row of actual data. Any thoughts on how to get past the "dirty" cells? Thanks in advance.

    AWBF

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: Excel can't find last row of data

    Maybe reset the used range

    http://www.contextures.com/xlfaqApp.html#Unused

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    08-24-2007
    Posts
    16

    Re: Excel can't find last row of data

    Thanks VBA Noob
    I added the module to my macro but it still does not clear the problem. I still get 3 lines below the data. Any other thoughts??

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: Excel can't find last row of data

    Not without taking a look at the workbook. Post the sheet removing any confidential info

    VBA Noob

  5. #5
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: Excel can't find last row of data

    Or see if this helps to determine the last cell instead of LastCell

    Dim LastCell As Range
    Set LastCell = Cells.Find(What:="*", After:=[A1], SearchDirection:=xlPrevious)
        MsgBox LastCell.Row
        MsgBox LastCell.Column
    VBA Noob

  6. #6
    Registered User
    Join Date
    08-24-2007
    Posts
    16

    Re: Excel can't find last row of data

    Thanks VBA Noob
    I tried the code and it finds the rows perfect. Now when I apply it to my formula I get an error. Error is:
    LastCell.Row=<Object Required>

    Dim LastCell As Range
        Set LastCell = Cells.Find(What:="*", After:=[A1], SearchDirection:=xlPrevious)
    
    Range("AJ2:BS2").Select
        Selection.Copy
        Range("AJ3").Select
        Range("AJ3:AJ" & LastCell.Row).Select
        ActiveSheet.Paste
        Application.CutCopyMode = False
    This is where I am a noob, not sure what I should be adding to the code???

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1