2
I’m making a code but since I’m still very green in the VBA I don’t know how to make it work. It’s very simple, I want to press a cell and it will change a Boolean between True and False.
When I load it puts TRUE, but then if you press there again, or exit the cell and select again it does not change to false!
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Dim mudancasAtivas As Boolean
If Not Intersect(Target, Range("E1:E1")) Is Nothing Then
With Target(1, 3)
If mudancasAtivas = True Then
mudancasAtivas = False
.value = mudancasAtivas
ElseIf mudancasAtivas = False Then
mudancasAtivas = True
.value = mudancasAtivas
End If
End With
End If
If Not Intersect(Target, Range("E2:E10000")) Is Nothing Then
If mudancasAtivas = True Then
Codexxx
End If
End If
End If
End Sub
Is there any easier or more viable way to do this and work?
You just declared the variable
mudancasAtivas, she’s not defined, so she’s not going to enter theIf..– Lucio Rubens
I even ran your code here, but could you describe better what you intend to do? I still can’t understand your goal.
– cantoni
I want when pressing E1 to change the variable to true if it is false or otherwise. Which is so if it’s true it runs the code below.. I can’t change the variable every time I press E1
– Enato