在我特别点击目标范围之前,Worksheet_Change(将目标作为范围)不会更改单元格 [英] Worksheet_Change(Byval target as range) does not change the cells until I click the target range spesifically
问题描述
我正在尝试编写一个VBA代码,该代码将根据另一个单元格更改为特定参数的事件的组合自动增加单元格E11中的值。
I am trying to write a VBA code that automatically augments the value in cell E11 based on a combination of the event of another cell changing to specific parameters.
我的问题是我编写的VBA代码是半自动执行的,而不是全自动执行的。是否有其他方法可以根据句子是否自动发生这些情况
My issue is that the VBA code I have written does this semi-automatically and not fully automatically. Is there any other way to make this occur automatically based on these if sentences
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
推荐答案
在Worksheet_change事件中定位多个单元格像本文中一样,同时使用Application.Intersect(Target,otherCell)同时。
To target more than one cell in the Worksheet_change event use Application.Intersect(Target, otherCell) as in this post.
这篇关于在我特别点击目标范围之前,Worksheet_Change(将目标作为范围)不会更改单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!