Automatic Macros

  • Thread starter Thread starter David Fredrickson
  • Start date Start date
D

David Fredrickson

How can I automatically initiate a macro when I switch tabs within a worksheet
 
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
 
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
 
Back
Top