VBA trigger macro on cell value change

前端 未结 4 1898
青春惊慌失措
青春惊慌失措 2020-12-17 05:07

This should be simple. When the value of a cell changes I want to trigger some VBA code. The cell (D3) is a calculation from two other cells =B3*C3. I have atte

4条回答
  •  北海茫月
    2020-12-17 05:23

    Or try

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim numdependences As Integer
    On Error Resume Next
    HasDependents = Target.Dependents.Count
    If Err = 0 Then
        If InStr(Target.Dependents.Address, "$D$3") <> 0 Then
            MsgBox "change"
        End If
    End If
    On Error GoTo 0
    End Sub
    

    You need the error control in case you change a cell that has not dependents.

提交回复
热议问题