Worksheet Level
There are 23 different events.
More details on how to add these events can be found here: VBA > Events > Worksheet Level
Event | Description | 365 | 21 | 16 | 13 | 10 | 07 |
Activate Cast (DocEvents_Event) | (Worksheet and Chart sheet) Occurs when this worksheet is selected. This should be used instead of the OnSheetActivate property. | Y | Y | Y | Y | Y | Y |
BeforeDelete | Occurs before the worksheet is deleted. | Y | Y | Y | Y | ||
BeforeDoubleClick | Occurs before any cell on this worksheet is double clicked. This should be used instead of the OnDoubleClick property. | Y | Y | Y | Y | Y | Y |
BeforeRightClick | Occurs before any cell is right mouse clicked. | Y | Y | Y | Y | Y | Y |
Calculate Cast (DocEvents_Event) | Occurs before any cell on this worksheet is re-calculated. This event will also capture table filter changes as long as the table has a Total Row enabled. This should be used instead of the OnCalculate property. | Y | Y | Y | Y | Y | Y |
Change | (Worksheet and Chart sheet) Occurs when any cell on this worksheet is changed either by the user or by an external link. This event is not fired if the value changes as the result of a calculation. This should be used instead of the OnEntry property. Passes a Range as a parameter for the range of cells that was changed. | Y | Y | Y | Y | Y | Y |
Deactivate | (Worksheet and Chart sheet) Occurs when the user moves focus to another worksheet. This event does not fire when the user moves between two windows displaying the same worksheet. | Y | Y | Y | Y | Y | Y |
FollowHyperLink | (Worksheet only) Occurs when you click any hyperlink on a worksheet. | Y | Y | Y | Y | Y | Y |
LensGalleryRenderComplete | Occurs when a callout gallery's icons have completely rendered (dynamic and static) | Y | Y | Y | Y | ||
MouseDown | (Chart sheet only) Occurs when a mouse button is pressed while the pointer is over an embedded chart or chart sheet | Y | Y | Y | Y | Y | Y |
MouseMove | (Chart sheet only) Occurs when the mouse pointer is moved over the chart | Y | Y | Y | Y | Y | Y |
MouseUp | (Chart sheet only) Occurs when a mouse button is released while the pointer is over an embedded chart or chart sheet | Y | Y | Y | Y | Y | Y |
PivotTableAfterValueChanges | Occurs after a cell or range of cells inside a pivot table are edited or recalculated (when cells contain formulas). | Y | Y | Y | Y | Y | |
PivotTableBeforeAllocateChanges | Occurs before changes are applied to a pivot table. | Y | Y | Y | Y | Y | |
PivotTableBeforeCommitChanges | Occurs before changes are committed against the OLAP data source for a pivot table. | Y | Y | Y | Y | Y | |
PivotTableBeforeDiscardChanges | Occurs before changes to a pivot table are discarded. | Y | Y | Y | Y | Y | |
PivotTableChangeSync | Occurs after changes to a pivot table. | Y | Y | Y | Y | Y | |
PivotTableUpdate | (Worksheet only) Occurs after a pivot table report is updated on a worksheet. | Y | Y | Y | Y | Y | Y |
Resize | (Chart sheet only) Occurs when a chart is resized | Y | Y | Y | Y | Y | Y |
SelectEvent | (Chart sheet only) Occurs when a chart element is selected | Y | Y | Y | Y | Y | Y |
SelectionChange | (Worksheet only) Occurs when the selection is changed on the worksheet. | Y | Y | Y | Y | Y | Y |
SeriesChange | (Chart sheet only) Occurs when a value of a chart data point changes. | Y | Y | Y | Y | Y | Y |
TableUpdate | Occurs after a query table connected to the Data Model is updated on a worksheet. | Y | Y | Y | Y |
VBA Sample
Private Sub Worksheet_Activate()
End Sub
Private Sub Worksheet_BeforeDelete()
End Sub
Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Range, _
ByRef Cancel As Boolean)
End Sub
Private Sub Worksheet_BeforeRightClick( _
ByVal Target As Range, _
ByRef Cancel As Boolean)
End Sub
Private Sub Worksheet_Calculate()
End Sub
Private Sub Worksheet_Change( _
ByVal Target As Range)
End Sub
Private Sub Worksheet_Deactivate()
End Sub
Private Sub Worksheet_FollowHyperlink( _
ByVal Target As Hyperlink)
End Sub
Private Sub Worksheet_LensGalleryRenderComplete()
End Sub
Private Sub Worksheet_PivotTableAfterValueChange( _
ByVal TargetPivotTable As PivotTable, _
ByVal TargetRange As Range)
End Sub
Private Sub Worksheet_PivotTableBeforeAllocateChanges( _
ByVal TargetPivotTable As PivotTable, _
ByVal ValueChangeStart As Long, _
ByVal ValueChangeEnd As Long, _
ByRef Cancel As Boolean)
End Sub
Private Sub Worksheet_PivotTableBeforeCommitChanges( _
ByVal TargetPivotTable As PivotTable, _
ByVal ValueChangeStart As Long, _
ByVal ValueChangeEnd As Long, _
ByRef Cancel As Boolean)
End Sub
Private Sub Worksheet_PivotTableBeforeDiscardChanges( _
ByVal TargetPivotTable As PivotTable, _
ByVal ValueChangeStart As Long, _
ByVal ValueChangeEnd As Long)
End Sub
Private Sub Worksheet_PivotTableChangeSync(ByVal Target As PivotTable)
End Sub
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub
Private Sub Worksheet_TableUpdate(ByVal Target As TableObject)
End Sub
Example
This example shows you how to add an item to the cell shortcut menu for all the cells in the range "A1:G200".
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, ByRef Cancel As Boolean)
For Each ctlcontrol In Application.CommandBars("cell").Controls
If ctlcontrol.Tag = "added" Then ctlcontrol.Delete
Next ctlcontrol
If Not Application.Intersect(Target, Range("A1:G200")) Is Nothing Then
With Application.CommandBars("cell").Controls.Add( _
Type:=msoCommandButton, before:=6, temporary:=True)
.OnAction = "ExtraCommand"
.Tag = "added"
End With
End If
End Sub
Public Sub ExtraCommand
'do something
End Sub
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext