List of available worksheet event in Excel:
A cell or range of cells (that contain formulas) inside a PivotTable are edited or recalculated. The
Worksheet_PivotTableAfterValueChangeprocedure is used for handling this event.
This event fires before changes are committed against the OLAP data source for a PivotTable. The
Worksheet_PivotTableBeforeCommitChangesprocedure is used for handling this event.
This event fires before changes to a PivotTable are discarded (user chosen to roll back the changes). The
Worksheet_PivotTableBeforeDiscardChangesprocedure 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
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.