+ Reply to Thread
Results 1 to 11 of 11

How to use Select Case for different parameters

  1. #1
    Registered User
    Join Date
    10-28-2014
    Location
    Long Beach, California
    MS-Off Ver
    2007
    Posts
    10

    How to use Select Case for different parameters

    Hello,

    I'm trying to create a macro in Excel VBA that will change the active sheet and cell whenever a particular cell is clicked in the current sheet. I currently have that working with no problems (see below).

    Please Login or Register  to view this content.
    As the above code lays out, when the user clicks on cell A4, cell A1 on sheet "Charts" becomes the active cell. My issue is that if the user clicks in cell A11, I want it to activate cell A28 on the Charts sheet; If the user clicks in cell A30, I want it to activate cell A50 on the Charts sheet...and so on. I could use the above code and just add another case for each instance, but that seems long and cumbersome and I feel like there's a better way. Let me know if you need more information. I appreciate all of your help. Thank you!
    Last edited by schmidtkicker; 10-28-2014 at 04:30 AM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,419

    Re: How to use Select Case for different parameters

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)


    One way
    Please Login or Register  to view this content.
    Why not use hyperlinks on sheet, then no code would be required.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: How to use Select Case for different parameters

    Couldnt you just lookup the cell clicked against a table of cells to activate?

    Im sure theres a better way to do this but at its simplest.....

    Please Login or Register  to view this content.
    then cycle through TargetCells until you find the cell thats been clicked and take the corresponding itemm from the ActivateCells array.

  4. #4
    Registered User
    Join Date
    10-28-2014
    Location
    Long Beach, California
    MS-Off Ver
    2007
    Posts
    10

    Re: How to use Select Case for different parameters

    Hey Andy,

    I tried your code (see below), but when I click on cell A4 and/or A11, nothing happens. Any ideas? Also, I suppose I could use hyperlinks, but I'm going for the "wow" factor here (long story). Pjwhitfield - I'm no where near the point of being able to use arrays.

    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,419

    Re: How to use Select Case for different parameters

    Here is a working version.

    Just select yellow cell on sheet1
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    10-28-2014
    Location
    Long Beach, California
    MS-Off Ver
    2007
    Posts
    10

    Re: How to use Select Case for different parameters

    yeah still not working...

    Please Login or Register  to view this content.

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,419

    Re: How to use Select Case for different parameters

    maybe you should post your non working example.

  8. #8
    Registered User
    Join Date
    10-28-2014
    Location
    Long Beach, California
    MS-Off Ver
    2007
    Posts
    10

    Re: How to use Select Case for different parameters

    sorry - here you go

    Test 10-28-2014.xlsm

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,419

    Re: How to use Select Case for different parameters

    Take of the check for single cell selection as you have merged cells.

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    10-28-2014
    Location
    Long Beach, California
    MS-Off Ver
    2007
    Posts
    10

    Re: How to use Select Case for different parameters

    ok that definitely worked. One last thing...how do I make it so that the new active cell is at the top of the scroll view? Example, when the macro brings you to "A50", it's at the bottom of the viewing pane - how do I automatically set it so it's at the top? Thank you!!

  11. #11
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,419

    Re: How to use Select Case for different parameters

    Include the True value for scroll parameter.

    Please Login or Register  to view this content.

+ 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] Need the proper syntax to use Case/Select Case in vba properly.
    By rbion in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-16-2013, 02:34 PM
  2. [SOLVED] Disregard case in VBA code. (UCase, LCase, Select Case)
    By Orestees in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 09-07-2012, 12:12 PM
  3. Case Select compile error "Case without case select"
    By coasterman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-23-2012, 06:50 AM
  4. Case Select....The alternative method for long "Select Case"
    By kimyap in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-22-2008, 01:24 AM
  5. Select case / case is, multiple arguments
    By Werner Rohrmoser in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-03-2006, 07:00 AM

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.6.0 RC 1