Excel Guides

How to Trigger an Event when a Worksheet is Deactivated in Excel

When a worksheet is deactivated in Excel, there are a few things that happen:

  1. The worksheet's Deactivate event is triggered.
  2. The workbook's SheetDeactivate event is triggered.
  3. The Application.ActiveWorkbook and Application.ActiveSheet properties are updated to reflect the new active workbook and worksheet.

Example: How to Trigger an Event when a Worksheet is Deactivated in Excel

Private Sub Worksheet_Deactivate() 

   'Do something when this worksheet is deactivated 

End Sub
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object) 

   'Do something when any worksheet is deactivated 

End Sub

Trigger an Event when a Worksheet is Deactivated in Excel

  • "Active" events are triggered when a sheet or workbook becomes active.
  • "Deactivate" events are triggered when a sheet or workbook becomes inactive.

The Difference between ActiveX and DeactiveX Events

"Active" events are triggered when a sheet or workbook becomes active. "Deactivate" events are triggered when a sheet or workbook becomes inactive. In other words, "Active" events happen before "Deactivate" events.

How to Use the Worksheet_Deactivate Event

  1. "Active" events are triggered when a sheet or workbook becomes active. "Deactivate" events are triggered when a sheet or workbook becomes inactive. In other words, "Active" events happen before "Deactivate" events.

Move beyond 

Excel

Get started with Causal today.
Build models effortlessly, connect them directly to your data, and share them with interactive dashboards and beautiful visuals.