Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 67
Default Run macro when Sheets are active

I would like to run a macro on about 12 of 31 sheets when they are
activated.
I was hoping I could do this without putting the macro in to each worksheet
code. Is it possible to do it.

--
Thank You in Advance
Ed Davis


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,533
Default Run macro when Sheets are active

Hi Ed

You can have the macro in the code sheet for ThisWorkbook. This macro will
run 'Your code' when Sheet1, Sheet2 and sheet4 is activated, but not if
Sheet3 is activated.

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim ShArr As Variant
Dim RunMacro As Boolean
ShArr = Split("Sheet1,Sheet2,Sheet4", ",") 'All sheets where macro shall run
For sCounter = 0 To UBound(ShArr)
If Sh.Name = ShArr(sCounter) Then
RunMacro = True
Exit For
End If
Next
If RunMacro = True Then
'Here goes your code
End If
End Sub

Regards,
Per

"Ed Davis" skrev i meddelelsen
...
I would like to run a macro on about 12 of 31 sheets when they are
activated.
I was hoping I could do this without putting the macro in to each
worksheet code. Is it possible to do it.

--
Thank You in Advance
Ed Davis


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 67
Default Run macro when Sheets are active

Thank you very much.
That did the trick.
Greatly appreciated


--
Thank You in Advance
Ed Davis
"Per Jessen" wrote in message
...
Hi Ed

You can have the macro in the code sheet for ThisWorkbook. This macro will
run 'Your code' when Sheet1, Sheet2 and sheet4 is activated, but not if
Sheet3 is activated.

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim ShArr As Variant
Dim RunMacro As Boolean
ShArr = Split("Sheet1,Sheet2,Sheet4", ",") 'All sheets where macro shall
run
For sCounter = 0 To UBound(ShArr)
If Sh.Name = ShArr(sCounter) Then
RunMacro = True
Exit For
End If
Next
If RunMacro = True Then
'Here goes your code
End If
End Sub

Regards,
Per

"Ed Davis" skrev i meddelelsen
...
I would like to run a macro on about 12 of 31 sheets when they are
activated.
I was hoping I could do this without putting the macro in to each
worksheet code. Is it possible to do it.

--
Thank You in Advance
Ed Davis




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
macro to find cell content in sheets and make sheet active Nigel Excel Discussion (Misc queries) 4 June 26th 14 02:38 PM
macro active sheet liem Excel Discussion (Misc queries) 1 January 18th 08 05:48 AM
Selecting Embedded charts in Active Sheets programmatically Barb Reinhardt Charts and Charting in Excel 5 January 15th 06 02:36 PM
MACRO with Active X G118 Excel Discussion (Misc queries) 0 December 15th 05 03:45 PM
In 3 active sheets in wkbk, determine& display the # of sheets that have data wrpalmer Excel Discussion (Misc queries) 1 November 4th 05 02:01 PM


All times are GMT +1. The time now is 05:54 AM.

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

About Us

"It's about Microsoft Excel"