Change Event

Microsoft Office Web Components Visual Basic

Private Sub Range_Change( )

Remarks

This event occurs after the EndEdit event; at this point, the data has already been changed and the change cannot be canceled.

This event requires the WithEvents keyword, so it cannot be used with VBScript or JScript.

Example

The following example updates a label control on a Visual Basic form when the value in cell A1 of Sheet1 in Spreadsheet1 changes.

Dim WithEvents rngRange1 As Range

Private Sub Form_Load()

    ' Set a variable to the range for which you want to capture
    ' the Change event.
    Set rngRange1 = Spreadsheet1.Worksheets("Sheet1").Range("A1")

End Sub

Private Sub rngRange1_Change()
    ' Change the caption of Label1 to the current value
    ' of cell A1.
    Label1.Caption = rngRange1.Value
End Sub