我正在尝试编写一个VBA代码,该代码会根据另一个单元格更改为特定参数的事件的组合自动增加单元格E11中的值。
我的问题是我编写的VBA代码半自动执行,而不是完全自动执行。有没有其他方法可以根据这些句子自动发生
Private Sub Worksheet_Change(ByVal Target As Range)
Set Actus = Range("B24")
Set Def_F = Range("E11")
If Target.Address = "$E$11" And Target.Value = "1" And Actus.Value = "CPTA" Then
MsgBox "Try Again"
Target.Value = "0"
ElseIf Target.Address = "$E$11" And Target.Value = "0" And Actus.Value = "DPTA" Then
MsgBox "Again, Again"
Target.Value = "1"
ElseIf Target.Address = "$B$24" And Target.Value = "CPTA" And Def_F.Value = "1" Then
MsgBox "Failed, Again"
Def_F.Value = "0"
ElseIf Target.Address = "$B$24" And Target.Value = "DPTA" And Def_F.Value = "0" Then
MsgBox "Having fun today?"
Def_F.Value = "1"
Else: Exit Sub
End If
End Sub
答案 0 :(得分:-1)
要在Worksheet_change事件中定位多个单元格,请使用Application.Intersect(Target,otherCell)as in this post。