如果单元格更改调用宏

时间:2018-04-24 10:51:42

标签: vba excel-vba excel

以下代码无效 - 请指导我

Private Sub worksheet_change(ByVal target As Range)
    Set target = Range("D11")
    If target.value = "Yes" Then
        Call main
    End If
    If target.value = "No" Then
        Call Main2
    End If
End Sub

1 个答案:

答案 0 :(得分:1)

也许你在此之后:

Private Sub Worksheet_Change(ByVal Target as Range) 
    If Target.Address <> "$D$11" Then Exit Sub ‘ if the changed cell is not $D$11 then do nothing

    If Target.Value = "Yes" Then
        Main
    ElseIf Target.Value = "No" Then
        Main2
    End If
End Sub