+ Reply to Thread
Results 1 to 5 of 5

Thread: Auto expand range based on first cell selection

  1. #1
    Registered User
    Join Date
    03-28-2011
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    7

    Auto expand range based on first cell selection

    Hi

    I need some help in selecting a long, but single column array of data. Currently I am using Application.InputBox to allow the user to select the required range. This works but is a tedious process as it must often be repeated and there can be up to 20,000 rows to scroll down.

    Is it possible to have the user select the first cell of the appropriate column then have VBA expand the rows of the range down, to including the remaining values? Please note that the data needed is not always in the same column, beginning on the same row or is the same length so any solution must be fairly generic.

    Thanks!
    Last edited by Jimmy Moggles; 03-29-2011 at 07:57 AM. Reason: SOLVED

  2. #2
    Forum Guru Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    5,590

    Re: Auto expand range based on first cell selection

    Have you tried selecting the first cell, then using the arrow keys while holding down Ctrl+Shift?

    f8 (extended selection) can also be handy
    Last edited by Marcol; 03-28-2011 at 04:41 AM.
    If you need any more information, please feel free to ask.

    However, if this takes care of your needs, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED. It helps everybody! ....
    Also
    If you are satisfied by any members response to your problem please consider using the small Star icon botom left of thier post to show your appreciation.

  3. #3
    Registered User
    Join Date
    03-28-2011
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Auto expand range based on first cell selection

    That is indeed very useful and something I wish I had known years ago! Ultimately the workbook will not be used by me however so I am trying to keep any user input to an absolute minimum to reduce possibility of error.

    If there were a way to program Ctrl+Shift+Down into VBA and have the result saved to a ranged variable I could then copy past ect, that would provide the functionality I need perfectly. This doesn't seem possible however as I can record these keystrokes in a macro but cannot then run it. Any suggestions?

  4. #4
    Forum Guru Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    5,590

    Re: Auto expand range based on first cell selection

    You could put this in the worksheet module but it will override everything so controlling it will be a problem
    Option Explicit
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Range(Selection, Selection.End(xlDown)).Select
    End Sub
    Probably better to use individual macros, here are two examples
    Sub ExtendRangeDown()
        Range(Selection, Selection.End(xlDown)).Select
    End Sub
    
    Sub ExtendRangeRight()
        Range(Selection, Selection.End(xlToRight)).Select
    End Sub

    Hope this helps
    If you need any more information, please feel free to ask.

    However, if this takes care of your needs, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED. It helps everybody! ....
    Also
    If you are satisfied by any members response to your problem please consider using the small Star icon botom left of thier post to show your appreciation.

  5. #5
    Registered User
    Join Date
    03-28-2011
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Auto expand range based on first cell selection

    Took a little bit of a work around, but managed it in the end. Thanks.

    FYI

    Set Time = Application.InputBox("Select first Time data value", "Select Time", , , , , , 8)
    Range(Time, Time.End(xlDown)).Select
    Set Time = Selection

+ 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.2.0