+ Reply to Thread
Results 1 to 5 of 5

When using the xlLastCell in VB it will go further than the last cell?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-08-2009
    Location
    Missouri
    MS-Off Ver
    Excel 2003
    Posts
    183

    When using the xlLastCell in VB it will go further than the last cell?

    It has to do with the fact that I am putting stuff in and then deleting it. xlLastCell will go to where the end of the last cell where the information used to be that I had deleted was. If that makes since..

    I have figured out that if I save the workbook it will update and then xlLastCell will work just fine.. The problem is, that when I use that, it slows down the execution of the macro tremendously..

    Any ideas? Is there something else that will update the workbook besides Save?

    Here is my code as of now, with the ActiveWorkbook.Save in there.

        Sheets("Pending Approvals").Select
        ActiveWorkbook.Save    
        Sheets("Blank Form").Select
        Application.CutCopyMode = False
        ActiveWorkbook.Save    
        Rows("1:65").Select
        Selection.COPY
        Sheets("Pending Approvals").Select
        Range("A1").Select
        ActiveCell.SpecialCells(xlLastCell).Select
        Cells(ActiveCell.Row + 1, 1).Activate
        ActiveSheet.Paste
        ActiveWindow.SmallScroll Down:=33
    Thanks for the help!
    Last edited by mrgillus; 08-20-2009 at 11:33 AM. Reason: Lining up the information in the code box..

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: When using the xlLastCell in VB it will go further than the last cell?

    perhaps see: http://www.rondebruin.nl/last.htm

  3. #3
    Forum Contributor
    Join Date
    07-08-2009
    Location
    Missouri
    MS-Off Ver
    Excel 2003
    Posts
    183

    Re: When using the xlLastCell in VB it will go further than the last cell?

    Yup well that confirms it. But I didn't really notice anything that would take care of this problem easily.. Looks like most of those codes just tell you where the last cell is (or was if you have deleted)

  4. #4
    Registered User
    Join Date
    08-19-2009
    Location
    Chicago, Illinois
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: When using the xlLastCell in VB it will go further than the last cell?

    Why do you save it twice? Why do you select two different sheets, with nothing but a save statement in between? It looks like the first two lines of the code you provided are superfluous, and if the save is the slow part, then getting rid of one out of two save statements would help somewhat.

    I know that isn't really an answer to the question you asked, but it sounded like you were going for code optimization due to a speed problem. You probably don't need to select cell A1 before the LastCell statement, either. Select statements slow code down in general.

    I hope this helps.

    ~telyni

  5. #5
    Forum Contributor
    Join Date
    07-08-2009
    Location
    Missouri
    MS-Off Ver
    Excel 2003
    Posts
    183

    Re: When using the xlLastCell in VB it will go further than the last cell?

    Thanks, I appreciate the help guys, and yeh I believe your correct.. I don't believe I need to save it twice.. For some reason I was thinking only the sheet it was on would update the last cell during save, not initially thinking that Save would update the entire workbook..

+ 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