excel VBA run macro automatically whenever a cell is changed

前端 未结 5 1641
礼貌的吻别
礼貌的吻别 2020-11-27 20:54

Is there a simple way to get Excel to automatically execute a macro whenever a cell is changed?

The cell in question would be in Worksheet(\"BigBoard\").Range(

5条回答
  •  星月不相逢
    2020-11-27 21:29

    In an attempt to spot a change somewhere in a particular column (here in "W", i.e. "23"), I modified Peter Alberts' answer to:

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Not Target.Column = 23 Then Exit Sub
        Application.EnableEvents = False             'to prevent endless loop
        On Error GoTo Finalize                       'to re-enable the events
        MsgBox "You changed a cell in column W, row " & Target.Row
        MsgBox "You changed it to: " & Target.Value
    Finalize:
        Application.EnableEvents = True
    End Sub
    

提交回复
热议问题