Consulting

Results 1 to 3 of 3

Thread: Run macro whenever you change sheets

  1. #1

    Run macro whenever you change sheets

    Hi all,

    I'm looking to write a macro that runs whenever I change sheets. Note, when I want it to run when I actually change sheets, not change something on the sheets. All the macro itself would do is search the sheet which you just left for cells with a certain color index and then update values in two specific cells depending on which color indexes were found. That part i can figure out, its the event handler that is giving me trouble. Is there a way to make the Workbook_Deactivate event handler apply to all sheets?

    Thanks,

    Brad

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)

    MsgBox Sh.Name & " refers to the sheet we came from"
    MsgBox ActiveSheet.Name & " refers to the sheet we are on"
    End Sub
    [/vba]

    This is workbook event code.
    To input this code, right click on the Excel icon on the worksheet
    (or next to the File menu if you maximise your workbooks),
    select View Code from the menu, and paste the code
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    XLD,

    Thanks a lot, works great.

    Brad

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •