Worksheet_Change(Byval target as range) does not change the cells until I click the target range spesifically

放肆的年华 提交于 2019-12-11 14:23:56

问题


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.

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

回答1:


To target more than one cell in the Worksheet_change event use Application.Intersect(Target, otherCell) as in this post.



来源:https://stackoverflow.com/questions/49438998/worksheet-changebyval-target-as-range-does-not-change-the-cells-until-i-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!