+ Reply to Thread
Results 1 to 9 of 9

Multiple conditions within Worksheet_SelectionChange(ByVal Target As Range)

  1. #1
    Registered User
    Join Date
    03-25-2004
    Posts
    54

    Multiple conditions within Worksheet_SelectionChange(ByVal Target As Range)

    Hey, guys. What's up?

    Please, I need some help from you, experts.

    I have 5 sheets and here is what I want to do:

    In Sheet1, if I click on A2, it goes to Sheet2. If I click on A3, it goes to Sheet3. If I click on A4, it goes to Sheet4. If I click on A5, it goes to Sheet5.
    In Sheet2, if I click on A1, it goes to Sheet1. If I click on A3, it goes to Sheet3. If I click on A4, it goes to Sheet4. If I click on A5, it goes to Sheet5.
    In Sheet3, if I click on A1, it goes to Sheet1. If I click on A2, it goes to Sheet2. If I click on A4, it goes to Sheet4. If I click on A5, it goes to Sheet5.
    In Sheet4, if I click on A1, it goes to Sheet1. If I click on A2, it goes to Sheet2. If I click on A3, it goes to Sheet3. If I click on A5, it goes to Sheet5.
    In Sheet5, if I click on A1, it goes to Sheet1. If I click on A2, it goes to Sheet2. If I click on A3, it goes to Sheet3. If I click on A4, it goes to Sheet4.

    As you may have noticed, the cells A1 to A5 work like buttons which lead to other sheets. These cells are big (width and height) with small texts in the middle of them. I could, but I DO NOT want to use hyperlinks, and the reason is very simple: if I use hyperlinks, I will have to click exactly on the TEXT to go to another sheet and this is very annoying. The way I'm trying to do is better because I can click on the cell itself, so even if I don't click on the TEXT of the cell, it will still work.

    I've already made this code:

    Please Login or Register  to view this content.
    This works perfectly, but there is only one condition and I need 4 of them. When I try to add more conditions, it won't work properly, certainly because I'm doing it the wrong way. Here it is:

    Please Login or Register  to view this content.
    By the way, I'm using macros (mcrGoToSheet#) because it does more things than just activate the sheet in question. Example:

    Please Login or Register  to view this content.
    So, what do I have to do to have multiple conditions within the Worksheet_SelectionChange event?

    I hope you can help me. Thanks a lot for you attention.

    brunces
    Last edited by brunces; 06-24-2014 at 07:56 PM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,627

    Re: Multiple conditions within Worksheet_SelectionChange(ByVal Target As Range)

    Option 1:
    Please Login or Register  to view this content.
    Option 2:
    Please Login or Register  to view this content.
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    03-25-2004
    Posts
    54

    Re: Multiple conditions within Worksheet_SelectionChange(ByVal Target As Range)

    protonLeah,

    Thank you very much for your answer.

    Although I have understood your point, I still have a doubt.

    My first post was just "an example", I mean, what I have here is not really the same. For example, my "buttons" are actually not in sequence, from A1 to A5. I explained my problem like that (A1 to A5) to make it simple. I just couldn't imagine you would use the row of the cell as part of the code (which, by the way, was awesome!). So, I appologize for that. I tried to make it simpler to explain, but that led to a (neat and intelligent) solution that, unfortunately, does not fit my needs exactly.

    Here in my sheets, the cells (buttons) are not in sequence. Each button is a random cell. For example:

    C3 = Button to go to Sheet2.
    C9 = Button to go to Sheet3.
    D15:D18 (merged cells) = Button to go to Sheet4.
    D27:D29 (merged cells) = Button to go to Sheet5.

    Well, that said, what would the code look like? Something like this? :P

    Please Login or Register  to view this content.
    Once again, I'm sorry. I tried to be simple, but it was not a good idea.

    Thanks a lot.

    brunces
    Last edited by brunces; 06-24-2014 at 08:56 PM.

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,627

    Re: Multiple conditions within Worksheet_SelectionChange(ByVal Target As Range)

    Select Case Target.Address(0, 0)
    Without the (0,0), you must use "$" in the Address string like
    Case "$C$3"

  5. #5
    Registered User
    Join Date
    03-25-2004
    Posts
    54

    Re: Multiple conditions within Worksheet_SelectionChange(ByVal Target As Range)

    Very cool! Thank you so much, protonLeah! I really appreciate your attention. Cheers.

  6. #6
    Registered User
    Join Date
    03-25-2004
    Posts
    54

    Re: Multiple conditions within Worksheet_SelectionChange(ByVal Target As Range)

    Hi, it's me again.

    I've run into a situation here... If, for any reason, somebody selects all the cells, the code goes crazy. Is there any way to avoid this kind of issue? I mean, macros must be run only if those specific cells are selected. If I select all the cells (or more cells than those specific ones), nothing should happen. Is that possible?

    Thanks, guys.

  7. #7
    Registered User
    Join Date
    06-12-2014
    Posts
    42

    Re: Multiple conditions within Worksheet_SelectionChange(ByVal Target As Range)

    Out of curiosity, why don't you just insert shapes such as rectangles, format them to look like the buttons you desire and assign your macros to them?

  8. #8
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,627

    Re: Multiple conditions within Worksheet_SelectionChange(ByVal Target As Range)

    Check for multiple cells selected:
    Please Login or Register  to view this content.
    rest of code continues below the check

  9. #9
    Registered User
    Join Date
    03-25-2004
    Posts
    54

    Re: Multiple conditions within Worksheet_SelectionChange(ByVal Target As Range)

    Wow! That's great, protonLeah. This is new to me. Thank you so much for your help. Cheers.

    Just for the record, I had to use it this way...

    Please Login or Register  to view this content.
    ... and it worked perfectly.
    Last edited by brunces; 06-25-2014 at 09:45 PM.

+ 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] Worksheet_SelectionChange(ByVal Target As Range) - Not Firing!
    By Break_Point in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2013, 06:44 AM
  2. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    By whitesapphire24 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-28-2011, 05:08 AM
  3. Worksheet_SelectionChange(ByVal Target As Range) questions
    By Gary Keramidas in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-02-2005, 06:05 AM
  4. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    By tawnee jamison in forum Excel General
    Replies: 0
    Last Post: 04-20-2005, 05:13 PM
  5. Ranges:Target in Worksheet_SelectionChange(ByVal Target As Range)
    By Kevin McCartney in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-15-2005, 09:06 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