+ Reply to Thread
Results 1 to 8 of 8

Range Selection Code Help

  1. #1
    Registered User
    Join Date
    02-23-2012
    Location
    FL
    MS-Off Ver
    Excel 2007
    Posts
    55

    Range Selection Code Help

    Hi Everyone, I have this selection code that works perfectly. It ensures all data in a column is selected (including blanks):



    Please Login or Register  to view this content.
    My problem comes when I want to have the Column select vary by using a string. I'm not sure how to incorporate it? I've tried with and without quotation marks with no luck. Anyone know how to do this?


    Please Login or Register  to view this content.

  2. #2
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Range Selection Code Help

    Quote Originally Posted by mattyp View Post
    Hi Everyone, I have this selection code that works perfectly. It ensures all data in a column is selected (including blanks):

    Do you mean, you are just trying to find a range that identifies the first cell to the last cell, in a given column?

    I would suggest using something like this:

    Please Login or Register  to view this content.
    But, it's a very good practice to identify the sheet you want to look at (as below).

    Please Login or Register  to view this content.
    Last edited by GeneralDisarray; 08-08-2016 at 02:05 PM.
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  3. #3
    Registered User
    Join Date
    02-23-2012
    Location
    FL
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: Range Selection Code Help

    Hi!! Sorry I forgot an important part of the code. "r" is the current rows letter value. My issue is I'm having trouble adding "r" to the line of code - the code below doesn't work no matter how I format it. I'm afraid I don't understand why either.

    Please Login or Register  to view this content.

  4. #4
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Range Selection Code Help

    Try using something like this:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-23-2012
    Location
    FL
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: Range Selection Code Help

    That worked perfect! Thank you General! Would you mind explaining how this script is able to select all the data? I've confirmed it works - I just don't fully understand.

  6. #6
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Range Selection Code Help

    The key is using 'Resize'.


    First, understand what this does: Cells(Rows.Count, "R").End(xlUp)

    It's equivalent selecting cell R1048576 with your mouse, pressing the 'end' button on your keyboard, then pressing the up arrow. If you do that, you will see your selection travel up to the last non-blank cell in column R.

    To find the row number, we just use .Row, so the code becomes Cells(Rows.Count, "R").End(xlUp).Row. But, you are starting in the second row (R2) - so we need to take 1 away from that number:


    Finally, we need to pass this number back to Resize() to tell Excel "I want to start in cell R2 and 'go' down this many rows - Cells(Rows.Count, "R").End(xlUp).Row -1. Then I want to select that result".

  7. #7
    Registered User
    Join Date
    02-23-2012
    Location
    FL
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: Range Selection Code Help

    That explains it perfectly! Thank you so very much for your time and assistance. It really is greatly appreciated.

  8. #8
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Range Selection Code Help

    Glad to be of help, please mark your thread 'solved'.

    (from FAQ)

    To mark your thread solved do the following:
    New Method
    -Go to the top of the first post
    -Select Thread Tools
    -Select Mark thread as Solved

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] code for data range selection to create a line graph in a macro
    By dominicm in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-17-2015, 09:35 AM
  2. range selection rows code replace
    By bezbid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-20-2015, 06:47 AM
  3. Create a code for offsetting range selection by 1 column
    By amartino44 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-04-2013, 12:56 PM
  4. [SOLVED] Range(Selection, Selection.End(xlDown)).Select goes to 65536 instead of last filled row
    By looney in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-12-2013, 10:51 AM
  5. [SOLVED] Range selection code
    By destijl03 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-22-2012, 12:49 AM
  6. code selection range
    By pichai in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-16-2008, 09:13 PM
  7. Range selection-How do I use vb code to pick up
    By Sagaron in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-16-2005, 07:08 AM

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