Posted on 2014-01-28
Last Modified: 2014-02-01

Generally I use the following to test if something is true/false then flip it, surely there is a one line method which will flip true/false..

    If Not ActiveSheet.Shapes("graphblur").Visible Then
        ActiveSheet.Shapes("graphblur").Visible = True
        ActiveSheet.Shapes("graphblur").Visible = False
    End If
Question by:DemonForce
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 10

Expert Comment

ID: 39815608
The XOR logical operation can do this.
If you XOR a bit with itself, it will flip.  (if you XOR a BYTE with itself, it will flip all the bits.)


ActiveSheet.Shapes("graphblur").Visible = ActiveSheet.Shapes("graphblur").Visible  Xor ActiveSheet.Shapes("graphblur").Visible

Accepted Solution

nick2253 earned 500 total points
ID: 39815669
The XOR operation with itself will most definitely not flip a bit.

You have to XOR a bit with 1 to flip a bit using XOR.  You can clearly see it from the XOR truth table:
1 XOR 1 = 0
1 XOR 0 = 1

Open in new window

(flipping the bit, what you want to achieve)

1 XOR 1 = 0
0 XOR 0 = 0

Open in new window

(always makes it 0, what you don't want)

ActiveSheet.Shapes("graphblur").Visible = True Xor ActiveSheet.Shapes("graphblur").Visible 

Open in new window

LVL 10

Expert Comment

ID: 39815703
Gosh,  you are abosultely right nick, one must Xor with 1, rather than itself to flip a value!

(So, what was I thinking about!?   Perhaps the swapping of two variables in memory?

Sorry about that!
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 47

Expert Comment

by:Martin Liss
ID: 39815741
ActiveSheet.Shapes("graphblur").Visible = Not ActiveSheet.Shapes("graphblur").Visible
LVL 10

Expert Comment

ID: 39821688
Face palm (again).
Martin's answer is the best.
LVL 47

Expert Comment

by:Martin Liss
ID: 39821708
Thanks Korbus, now hopefully DemonForce will agree:)

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question