Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default 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   Report Post  
Posted to microsoft.public.excel.programming
Ian Ian is offline
external usenet poster
 
Posts: 238
Default 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
--
wrote in message
oups.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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default 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   Report Post  
Posted to microsoft.public.excel.programming
Ian Ian is offline
external usenet poster
 
Posts: 238
Default 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 EditFind to
locate the macro name (search in Current Project). Just cut and paste it.

--
Ian
--
wrote in message
oups.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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sheet activation CWillis Excel Discussion (Misc queries) 5 June 1st 06 09:50 PM
Sheet protection error msg - Unrequested sheet activation deltree[_3_] Excel Programming 0 January 28th 04 06:20 PM
Excel macro activation. Pete McCosh[_3_] Excel Programming 0 July 29th 03 04:59 PM
Excel macro activation. Dick Kusleika Excel Programming 0 July 29th 03 04:47 PM
Excel macro activation. Dave Ramage[_2_] Excel Programming 0 July 29th 03 04:47 PM


All times are GMT +1. The time now is 02:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"