Posted on 2014-01-28
Medium Priority
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 2000 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!
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 49

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 49

Expert Comment

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

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

801 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