+ Reply to Thread
Results 1 to 4 of 4

macro on Sheet activation

Hybrid View

  1. #1
    keyser_Soze@usa.com
    Guest

    macro on Sheet activation

    I have a macro I would like to run each time I switch to a specific
    sheet. How can I set this up?

    Thanks.


  2. #2
    Ian
    Guest

    Re: macro on Sheet activation

    Assign the code to Worksheet Activate

    eg This macro toggles A1 between 0 & 1 each time the sheet is activated

    Private Sub Worksheet_Activate()
    If Range("A1").Value = 0 Then
    Range("A1").Value = 1
    Else
    Range("A1").Value = 0
    End If
    End Sub

    --
    Ian
    --
    <keyser_Soze@usa.com> wrote in message
    news:1125267827.301302.105420@g14g2000cwa.googlegroups.com...
    >I have a macro I would like to run each time I switch to a specific
    > sheet. How can I set this up?
    >
    > Thanks.
    >




  3. #3
    keyser_Soze@usa.com
    Guest

    Re: macro on Sheet activation

    So, to be clear, if I change the name to Worksheet_Activate, this will
    run on each activation. If instead, I need to set the worksheet
    activate event to point to my macro, that is what I need to know how
    to do.

    Thanks.


  4. #4
    Ian
    Guest

    Re: macro on Sheet activation

    If you rigth click on the sheet tab and click View Code, this will open VBA
    editor. In the left pane, double click on the sheet you want to run the code
    in then, above the code window select Worksheet in the LH drop-down and
    Activate in the RH one. This will create the Worksheet_Activate subroutine
    framework (1st & last lines of my code). This is where your code needs to
    go. I don't know exactly where your code will be, but it could well be in a
    module which will be listed in the LH pane. If not you can use Edit>Find to
    locate the macro name (search in Current Project). Just cut and paste it.

    --
    Ian
    --
    <keyser_Soze@usa.com> wrote in message
    news:1125270295.215433.105290@g47g2000cwa.googlegroups.com...
    > So, to be clear, if I change the name to Worksheet_Activate, this will
    > run on each activation. If instead, I need to set the worksheet
    > activate event to point to my macro, that is what I need to know how
    > to do.
    >
    > Thanks.
    >




+ 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