I have a macro I would like to run each time I switch to a specific
sheet. How can I set this up?
Thanks.
I have a macro I would like to run each time I switch to a specific
sheet. How can I set this up?
Thanks.
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.
>
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.
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.
>
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks