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
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
Ed wrote:
> 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
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
"Ed" <ed_millis@NO_SPAM.yahoo.com> wrote in message
news:u1IhebhEGHA.3856@TK2MSFTNGP12.phx.gbl...
> 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
>
>
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
"Chip Pearson" <chip@cpearson.com> wrote in message
news:OP7vRqhEGHA.2040@TK2MSFTNGP14.phx.gbl...
> 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
>
>
>
> "Ed" <ed_millis@NO_SPAM.yahoo.com> wrote in message
> news:u1IhebhEGHA.3856@TK2MSFTNGP12.phx.gbl...
>> 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
>>
>>
>
>
Thanks, Chip.
"Chip Pearson" <chip@cpearson.com> wrote in message
news:eV2f0rhEGHA.2648@TK2MSFTNGP11.phx.gbl...
> 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
>
>
>
> "Chip Pearson" <chip@cpearson.com> wrote in message
> news:OP7vRqhEGHA.2040@TK2MSFTNGP14.phx.gbl...
> > 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
> >
> >
> >
> > "Ed" <ed_millis@NO_SPAM.yahoo.com> wrote in message
> > news:u1IhebhEGHA.3856@TK2MSFTNGP12.phx.gbl...
> >> 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
> >>
> >>
> >
> >
>
>
Thanks, Bill.
"Bill Martin" <wylie@earthlink.net> wrote in message
news:eQ38ckhEGHA.1816@TK2MSFTNGP11.phx.gbl...
> Ed wrote:
> > 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
14 years ago, but the issue still.
Excel VBA
A = 1
A = NOT A
A results in -2
A = NOT A
A results in +1, and keeps flipping between +1 and -2.
Why is that? Why not flips between 1 and 0 ?
I use
A = ABS(A-1) to flip between 1 and 0 faster, but thought NOT could do it too.
using XOR also gives me what I need,
A = A XOR 1
Flips between 1 and 0 nicely, but still using one extra argument than NOT.
Administrative Note:
Welcome to the forum.
We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.
Please see Forum Rule #4 about hijacking and start a new thread for your query.
If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
2. If your question is resolved, mark it SOLVED using the thread tools
3. Click on the star if you think someone helped you
Regards
Ford
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks