+ Reply to Thread
Results 1 to 11 of 11

How to select the last cell in a currently selected range

  1. #1
    Valued Forum Contributor
    Join Date
    09-04-2007
    Location
    Ontario, Ca
    Posts
    624

    How to select the last cell in a currently selected range

    The following code selects all cells from Q12 through the last data row of database.

    Let's assume the last row of data is row 300. After the cells of Q12 thru Q300 are selected, I want the active cell to be 1 cell below the last data row. The previous selection is then no longer needed.

    My request is for a diffeent need, than what this code is used for else where..

    Please Login or Register  to view this content.
    Thanks for the help
    Matt
    Last edited by Launchnet; 11-20-2011 at 05:11 PM.
    Thanks for helping . . .
    Matt @ Launchnet

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: How to select the last cell in a currently selected range

    Try this,

    Please Login or Register  to view this content.

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to select the last cell in a currently selected range

    A quick way to select the first empty cell in column Q by looking UP from the bottom of the worksheet:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Valued Forum Contributor
    Join Date
    09-04-2007
    Location
    Ontario, Ca
    Posts
    624

    Re: How to select the last cell in a currently selected range

    Thanks for the try. I forgot to say that there are blank cells in various cells, so I can't use either method. I happen to know these two ways, but I don't know how to get around the blank cells. The sample code I'm using selects all cells including empty cells, all the way down to and including the last data row of the database.

    Please take another look

    Thanks

    Matt

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to select the last cell in a currently selected range

    Hello Matt,

    A minor change is all that is needed.
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 11-20-2011 at 01:45 AM.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  6. #6
    Valued Forum Contributor
    Join Date
    09-04-2007
    Location
    Ontario, Ca
    Posts
    624

    Re: How to select the last cell in a currently selected range

    Good Morning Leith . . . Good To See Your Name

    Only 1 problem . . .

    Column Q does not always have data in any particular cell. There currently happens to be 8 blank cells in column Q at the bottom. Some cells in Column Q will never have data. This causes me a problem, as I need to have the last data row, in column Q, selected. Then, I can move the selection down 1 cell and then move it to column "A" on the same blank row or record.

    I need this macro so that I can add a new record in the 1st row after the current data row.

    Hope that I have explained this to where it can be understood.

    Thanks Much

    Matt

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to select the last cell in a currently selected range

    Hello Matt,

    You are up early this morning. If "Q" extends to the end of the database then maybe this change is what you need. This will select one row below the last row of the database.
    Please Login or Register  to view this content.

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: How to select the last cell in a currently selected range

    You should avoid 'Select' & 'Activate' in VBA

    you could use:

    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.



  9. #9
    Valued Forum Contributor
    Join Date
    09-04-2007
    Location
    Ontario, Ca
    Posts
    624

    Re: How to select the last cell in a currently selected range

    Hi Leith . . .

    I copied and pasted your code and as I press F8 to start stepping thru, I get a VB Compile error: Method or data member not found. The code Set Rng = Wks.cell(RngEnd.Row + 1, "G") has the .cell high-lited.

    Thanks Again
    Matt
    Last edited by Launchnet; 11-20-2011 at 04:52 PM. Reason: Forgot info

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to select the last cell in a currently selected range

    Hello Matt,

    Looks like my bad typing skills are to blame.
    Please Login or Register  to view this content.

  11. #11
    Valued Forum Contributor
    Join Date
    09-04-2007
    Location
    Ontario, Ca
    Posts
    624

    Re: How to select the last cell in a currently selected range

    Right on the Money

    I added
    Please Login or Register  to view this content.
    and the cell selected is column A same row as you 1st selected.

    Many Thanks

    Matt

+ 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