+ Reply to Thread
Results 1 to 11 of 11

select range based on a cell value

  1. #1
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    select range based on a cell value

    I have a worksheet with a block of data. The size of this block changes. I am calculating and storing the upperleft and lower right cell position of the block in say cells AA3 and AB3 on the same worksheet.
    So far I have everything working fine.
    Now I want to create a button to trigger a macro to sort that block.
    I can figure out the button and make it trigger a macro.
    One of the lines in the macro is

    Please Login or Register  to view this content.
    How do I make it so this line looks at cells AA3 and AB3 to find the range instead of A3 and J23 ?

    I don't know the syntax in VBA.

    Thanks for your help.
    modytrane
    Last edited by VBA Noob; 09-18-2008 at 12:38 PM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430
    Try this, although usually selection of a range is not required to perform further coding against.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    select range based on cell value

    Didn't work.
    I got an error msg:

    Run time eoor 1004
    Method 'Range' of object '_Global' failed.

    modytrane

  4. #4
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127
    Why not try an approach like the one below. It determines the last row and the last column in the used range, and sorts accordingly.

    Report back

    Please Login or Register  to view this content.

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430
    works for me.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    select range based on cell value

    Thanks for your reply.

    However my situation is a little different.
    I actually have three blocks of data on one sheet.
    Each block will vary in size [upper left cell and lower right cell].
    I am calcualting these corner cells based on titles of each block.
    These corner cell values are stored in a fixed area of the worksheet.

    I wanted a way for VBA to read those cell values and insert them in the
    range (.........).Select statement.

    Hope this makes it clear.
    Thanks for your help,
    modytrane

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430
    rather than make us exhaust our psychic powers post an example of your data and explain your problem rather than a subset of it.

  8. #8
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    select range based on cell value

    Ok here's the example file.

    Cells AJ3:AK5 store the range values.
    As you can see the three blocks under John, Andy and Bill will change in size as accounts are added or deleted. Width will remain same.

    I have Macro1 created with your suggested code.

    I know this will be easy for you.

    Thanks,
    modytrane
    Attached Files Attached Files

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430
    The cells you gave as the source of information was incorrect.
    So not AA3 and AB3 but AJ3 and AK3.

    Please Login or Register  to view this content.
    Your sort is done on J3 which is not going to be applicable to all section.
    So try changing the key to

    Please Login or Register  to view this content.
    although only the first bank of data has information in column J

  10. #10
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    select range based on cell value

    Thanks Andy for your esponse and time.

    I never got your formula to work, even with correct reference info.
    I did pick up some clues from posts by you and BigBas and used this code which does the sorting for all three blocks.

    Please Login or Register  to view this content.

  11. #11
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430
    I added a random number to column J to give the data something to sort on.
    This worked for me.

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

+ 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. count cells in a range based on another cell
    By magicsticvi in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-14-2007, 03:40 PM
  2. Getting "Method 'Range' of Object '_Global Failed" with Range...Select
    By murpat01 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 05-14-2007, 03:51 PM
  3. Conditional Format a cell based on a range of numbers
    By fablhof in forum Excel General
    Replies: 2
    Last Post: 04-27-2007, 11:39 PM
  4. Change cell background based on another cell
    By ssmith001 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-12-2007, 05:19 PM
  5. Code to select a range of cells based on cursor location
    By kys2000 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-08-2007, 05:57 PM

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