+ Reply to Thread
Results 1 to 3 of 3

Command Button - Select Range

  1. #1
    Registered User
    Join Date
    04-01-2010
    Location
    Orlando, FL
    MS-Off Ver
    Excel 2007
    Posts
    36

    Command Button - Select Range

    Hi,

    I am having trouble making a command button on a worksheet select a new worksheet and range. The code is below...

    Please Login or Register  to view this content.
    or a longer way

    Please Login or Register  to view this content.
    Both of these create errors. If I take off the range selection I can get to the sheet.

    But how can I make it select the range also?

    Thank you.

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

    Re: Command Button - Select Range

    The big question is why are you trying to select a cell with VBA? There are few reasons to actually select a cell prior to doing something in/to that cell. If you wanted to put a value in a particular cell on a particular cell, just do it directly without selecting first:

    Please Login or Register  to view this content.

    If you've learned to "select" from looking at macro recorder code, that's the first thing that should be edited out of all recorded code. The recorder records what we humans are doing step by step, not the right way to do it. Code is far more efficient once all the selecting is taken out and commands are issued directly the cells/ranges.
    _________________
    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!)

  3. #3
    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: Command Button - Select Range

    Hello jonhfl,

    To activate the worksheet and the make the cell you want the active cell, you can use Application.GoTo. The Scroll argument will place the cell in the upper left hand corner of the worksheet when true. Selects any range or Visual Basic procedure in any workbook, and activates that workbook if it’s not already active.
    Please Login or Register  to view this content.
    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!)

+ 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