ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Automatic Macros (https://www.excelbanter.com/excel-worksheet-functions/228231-automatic-macros.html)

David Fredrickson

Automatic Macros
 
How can I automatically initiate a macro when I switch tabs within a worksheet

Sheeloo

Automatic Macros
 
Right-click the Sheetname and select 'View Code'...
In the VB Editor put your code between

Private Sub Worksheet_Activate()

End Sub

this will be executed everytime the sheet is activated

"David Fredrickson" wrote:

How can I automatically initiate a macro when I switch tabs within a worksheet


Bob Phillips[_3_]

Automatic Macros
 

Private Sub Workbook_SheetActivate(ByVal Sh As Object)

Select Case Sh.Name

Case "Sheet1": 'do something
Case "Sheet2": 'do something else
End Select
End Sub

'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


--
__________________________________
HTH

Bob

"David Fredrickson" <David wrote in
message ...
How can I automatically initiate a macro when I switch tabs within a
worksheet





All times are GMT +1. The time now is 08:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com