Results 1 to 9 of 9

Multiple conditions within Worksheet_SelectionChange(ByVal Target As Range)

Threaded View

  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:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Not Intersect(Target, Range("A2")) Is Nothing Then
            mcrGoToSheet2
        End If
    End Sub
    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:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Not Intersect(Target, Range("A2")) Is Nothing Then
            mcrGoToSheet2
        ElseIf Not Intersect(Target, Range("A3")) Is Nothing Then
            mcrGoToSheet3
        ElseIf Not Intersect(Target, Range("A4")) Is Nothing Then
            mcrGoToSheet4
        ElseIf Not Intersect(Target, Range("A5")) Is Nothing Then
            mcrGoToSheet5
        End If
    End Sub
    By the way, I'm using macros (mcrGoToSheet#) because it does more things than just activate the sheet in question. Example:

    Sub mcrGoToSheet2()
        Sheets("Sheet2").Activate
        Application.OnTime Now() + TimeValue("00:00:02"), "mcrPanelHideShow"
    End Sub
    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.

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. [SOLVED] 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