+ Reply to Thread
Results 1 to 5 of 5

Capturing what tab was selected

  1. #1
    MicroMain
    Guest

    Capturing what tab was selected

    I have a macro that is invoked when leaving a tab (deactivate), to
    clear off some data and do some other functions on that sheet, before
    moving to other sheets.

    I want to capture the tab that was selected, and then at the end of the
    macro, auto select the sheet that they clicked.

    Can someone please give me the command for capturing the clicked sheet?

    Thanks


  2. #2
    Ken Johnson
    Guest

    Re: Capturing what tab was selected

    Is that Rick?
    ActiveSheet.Name returns the name of the worksheet whose tab was
    clicked, deactivating the Sheet with the Worksheet_deactivate code.
    Ken Johnson


  3. #3
    Ken Johnson
    Guest

    Re: Capturing what tab was selected

    Your code must be reactivating the original sheet, otherwise it would
    automatically end up on the sheet whose tab was clicked.
    Here's a bit of code residing in the sheet1 module that places the
    clicked sheet's name in a string variable (strClickedSht), throws up a
    MsgBox with the clicked sheet's name, reactivates Sheet1, selects A1 on
    Sheet1 then activates the Sheet whose tab was clicked.

    Private Sub Worksheet_Deactivate()
    Dim strClickedSht As String
    strClickedSht = ActiveSheet.Name
    MsgBox ActiveSheet.Name
    Sheet1.Activate
    Sheet1.Range("A1").Select
    Application.EnableEvents = False
    Worksheets(strClickedSht).Activate
    Application.EnableEvents = True
    End Sub

    Ken Johnson


  4. #4
    MicroMain
    Guest

    Re: Capturing what tab was selected

    Thanks again Ken,

    I've put the code (without the Msg box stuff) into the macro and it
    works Marvelously.

    Thanks

    You are 'da Man


  5. #5
    Ken Johnson
    Guest

    Re: Capturing what tab was selected

    Hi Rick,
    That's good news.
    Keep up the good work.
    Ken Johnson


+ 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