"bisecting" loop with boolean flags
Dear John & Niek,
thanks a bunch for your input, I had no idea I needed to declare a static
variable. I did as you suggested, John, but unfortunately, the procedure
still doesn't toggle anywhere away from FALSE. Could there be any other
points I should take into consideration? I am running the procedure from
general code module (not a worksheet one).
Thanks in advance
Henrik
"John Coleman" wrote:
You have declared Flg to be a local (private) variable to the
procedure. You need a public variable. In a general code module,
outside of any sub or function, have the line
Public Flg as Boolean
and delete the line
Dim Flg as Boolean
from your code. This will toggle back and forth, It will start false
when you open Excel or whenever you reset the project. If you want
persistence across sessions you need to do something like hide the flag
in an out-of-the-way cell or something fancier like a registry setting
or entry in the names collection.
HTH
-John Coleman
Kragelund wrote:
Help pls! I need a procedure which can help me to select a selection A and B
respectively, so that selection A is chosen every other time the procedure
runs (and the same for selection B). I intended to make a procedure that sets
the flag to TRUE when the flag is FALSE and vice versa. In the code presented
below, the boolean value remains FALSE and never changes to TRUE.
What I am doing wrong??
Public Sub Insert_Flag()
Dim Worksheet As Worksheet
Dim Flg As Boolean
Set Worksheet = ActiveSheet
Select Case Flg
Case Flg = True (Selection A)
Flg = False
If Flg = False Then Cells(1, 3) = False
Case Flg = False (Selection B)
Flg = True
If Flg = True Then Cells(1, 3) = True
End Select
End Sub
|