Single command to toggle a Boolean?

E

Ed

In Excel 2000 VBA, is there one single command to toggle a Boolean - that
is, in whatever state it's in, change it to the opposite? I know it can be
done with an If / Else - I was just wondering if there was a singe-line way
to do it.

Ed
 
B

Bill Martin

Ed said:
In Excel 2000 VBA, is there one single command to toggle a Boolean - that
is, in whatever state it's in, change it to the opposite? I know it can be
done with an If / Else - I was just wondering if there was a singe-line way
to do it.

Ed

----------------

Dim Flag as Boolean
Flag = not(Flag)

Bill
 
C

Chip Pearson

Ed,

Use the Not operator. This will switch a boolean to its opposite.
E.g,

Dim Var As Boolean Dim Var As Boolean
Var = Not Var


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
C

Chip Pearson

I have no idea how I got two Dim statements in the code. The
code should have only one Dim Statement.

Dim Var As Boolean
Var = Not Var


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
E

Ed

Thanks, Chip.

Chip Pearson said:
I have no idea how I got two Dim statements in the code. The
code should have only one Dim Statement.

Dim Var As Boolean
Var = Not Var


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top