+ Reply to Thread
Results 1 to 6 of 6

How to reset xlCellsTypeLastCell when clearing a worksheet?

  1. #1
    Registered User
    Join Date
    07-16-2012
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    3

    How to reset xlCellsTypeLastCell when clearing a worksheet?

    I want to clear a worksheet without deleting it (so formulas on other sheets referring to it don't dereference). Using a command like
    Please Login or Register  to view this content.
    looks like it clears everything, but a subsequent
    Please Login or Register  to view this content.
    still moves to the previous last cell, not A1. When I later add data to the sheet that doesn't fill the previous area the xlCellTypeLastCell designation is useless. The same problem occurs when using the Ctrl+End keyboard shortcut. I haven't found any deletion method that doesn't have this quirk.

    Suggestions?

    Henry

  2. #2
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: How to reset xlCellsTypeLastCell when clearing a worksheet?

    Can you post a sample of the code you are using. I have never used xlCellTypeLastCell. Why dont you use a row.count reference?

  3. #3
    Registered User
    Join Date
    07-16-2012
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: How to reset xlCellsTypeLastCell when clearing a worksheet?

    Quote Originally Posted by fredlo2010 View Post
    Can you post a sample of the code you are using. I have never used xlCellTypeLastCell.
    Here's an example:
    Please Login or Register  to view this content.
    The active cell is then the empty cell C10, not A1.


    Quote Originally Posted by fredlo2010 View Post
    I have never used xlCellTypeLastCell. Why dont you use a row.count reference?
    Rows.Count requires a selection of the desired range, but the point is that I am trying to determine the range. Apparently, if used without a range it exhibits the same problem; it goes to the last row of the sheet before it was cleared, if that has a higher row number than the current data in the sheet occupy. The problem exists with any Ctrl+ Arrow Key combination (or the xl equivalents in code), not just xlCellTypeLastCell (or its alias, xlLastCell).

    I am currently workong around the problem by selecting the first cell in a column that I know has contiguous data in all its rows, and using Application.WorksheetFunctions.COUNT (or COUNTA) to find the last row.

    Thanks, but I'm still trying for a better solution, in case I don't have a solid column I can count on. (Pardon the pun.)

    Henry

  4. #4
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: How to reset xlCellsTypeLastCell when clearing a worksheet?

    maybe something like
    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: How to reset xlCellsTypeLastCell when clearing a worksheet?

    I cannot tell because I am not looking at you code. But you should not be using Select for anything there is no need.

  6. #6
    Registered User
    Join Date
    07-16-2012
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: How to reset xlCellsTypeLastCell when clearing a worksheet?

    Quote Originally Posted by nilem View Post
    maybe something like
    Please Login or Register  to view this content.
    That does it! Apparently finding the UsedRange resets the target of the ctrl + Arrow Keys and End operations.


    THANKS VERY MUCH

    Henry

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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