List of available worksheet event in Excel:
Activate
The worksheet is activated. TheWorksheet_Activate
procedure is used for handling this event.BeforeDelete
The worksheet is about to be deleted. TheWorksheet_BeforeDelete
procedure is used for handling this event.BeforeDoubleClick
The worksheet is double-clicked. This event occurs before the default double-click action. TheWorksheet_BeforeDoubleClick
procedure is used for handling this event.BeforeRightClick
The worksheet is right-clicked. This event occurs before the default right-click action. TheWorksheet_BeforeRightClick
procedure is used for handling this event.Calculate
The worksheet is calculated or recalculated. TheWorksheet_Calculate
procedure is used for handling this event.Change
Cells on the worksheet are changed by the user or by an external link. TheWorksheet_Change
procedure is used for handling this event.Deactivate
The worksheet is deactivated. TheWorksheet_Deactivate()
procedure is used for handling this event.FollowHyperlink
A hyperlink on the worksheet is clicked. TheWorksheet_FollowHyperlink
procedure is used for handling this event.LensGalleryRenderComplete
A callout gallery has finished rendering all icons. TheWorksheet_LensGalleryRenderComplete
procedure is used for handling this event.PivotTableAfterValueChange
A cell or range of cells (that contain formulas) inside a PivotTable are edited or recalculated. TheWorksheet_PivotTableAfterValueChange
procedure is used for handling this event.PivotTableBeforeAllocateChanges
This event fires before changes are applied to a PivotTable. TheWorksheet_PivotTableBeforeAllocateChanges
procedure is used for handling this event.PivotTableBeforeCommitChanges
This event fires before changes are committed against the OLAP data source for a PivotTable. TheWorksheet_PivotTableBeforeCommitChanges
procedure is used for handling this event.PivotTableBeforeDiscardChanges
This event fires before changes to a PivotTable are discarded (user chosen to roll back the changes). TheWorksheet_PivotTableBeforeDiscardChanges
procedure is used for handling this event.PivotTableChangeSync
A pivot table on the worksheet has changed or has been refreshed. TheWorksheet_PivotTableChangeSync
procedure is used for handling this event.PivotTableUpdate
A pivot table on the worksheet is updated. TheWorksheet_PivotTableUpdate
procedure is used for handling this event.SelectionChange
The selection on the worksheet is changed. TheWorksheet_SelectionChange
procedure is used for handling this event.TableUpdate
A query table on the sheet has completed updating data from the internal data model. TheWorksheet_TableUpdate
procedure is used for handling this event.
Writing the Worksheet Event Code
Worksheet event procedures must be entered into the code module for the worksheet. Each worksheet comes with its own built-in module, these code modules have default names like Sheet1
, Sheet2
, Sheet3
and so on. To open a code module, right click on its worksheet tab and select View Code
, as shown in following figure:
Immediately after you select View Code
, you are taken directly into the VBE (Visual Basic Editor) where you can start entering the event procedure code.
Immediately above the Code window you'll see two dropdown lists. The first dropdown list says (General)
is called "Object List Box" and the second one says (Declarations)
is called "Procedure List Box". Click the Object
(first dropdown) list and select the Worksheet
. It will write the Worksheet_SelectionChange
event procedure on the coding area. Now all the Event procedures are available on the second dropdown list as shown in following figure:
In next tutorials we'll read about the Worksheet events by writing some examples for each event procedure.