+ Reply to Thread
Results 1 to 3 of 3

Thread: Select sub based on which cell is currently active

  1. #1
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2007
    Posts
    262

    Select sub based on which cell is currently active

    I have 2 subs that I'd like to execute based on what cell is currently active in the worksheet. So for example, if one of the cells in range A1:D1 is active, upon pressing a button, sub1 will run, if one of the cells in range A5:D5 is currently active, upon pressing a button, sub2 will run.

    How can this be coded?

    Thank you.
    Last edited by luv2glyd; 09-04-2010 at 11:52 AM.
    You either quit or become really good at it. There are no other choices.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    11,351

    Re: how to run a select sub based on which cell is currently active

    Sub Button1_Click()
    
        If Not Intersect(Range("A1"), ActiveCell) Is Nothing Then
            MsgBox "Sub 1"
        ElseIf Not Intersect(Range("A2"), ActiveCell) Is Nothing Then
            MsgBox "Sub 2"
        Else
            MsgBox "Do nothing"
        End If
        
    End Sub
    Cheers
    Andy
    www.andypope.info

  3. #3
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2007
    Posts
    262

    Re: how to run a select sub based on which cell is currently active

    Perfect; thank you!
    You either quit or become really good at it. There are no other choices.

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