jeudi 22 mars 2018

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

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 spesific parameteres.

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

Aucun commentaire:

Enregistrer un commentaire