ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run a macro when changing the sheet (https://www.excelbanter.com/excel-programming/380227-run-macro-when-changing-sheet.html)

S. G.

Run a macro when changing the sheet
 
I would like a macro to run every time the user changes of sheet.
Not when a cell is selected or changed, but immediately after changing the
sheet.
I want it to run also when a new sheet is added to the workbook.

Thank you in advance.

Mike

Run a macro when changing the sheet
 


Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)

Put your macro here

End Sub

"S. G." wrote:

I would like a macro to run every time the user changes of sheet.
Not when a cell is selected or changed, but immediately after changing the
sheet.
I want it to run also when a new sheet is added to the workbook.

Thank you in advance.


excelent

Run a macro when changing the sheet
 
Put these in ThisWorkbook

Private Sub Workbook_NewSheet(ByVal Sh As Object)
MsgBox ("New")
End Sub

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
MsgBox ("Activated :") & Sh.Name
End Sub



"Mike" skrev:



Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)

Put your macro here

End Sub

"S. G." wrote:

I would like a macro to run every time the user changes of sheet.
Not when a cell is selected or changed, but immediately after changing the
sheet.
I want it to run also when a new sheet is added to the workbook.

Thank you in advance.



All times are GMT +1. The time now is 01:19 PM.

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