+ Reply to Thread
Results 1 to 5 of 5

Boolean Values in IF Statements

  1. #1
    Registered User
    Join Date
    09-16-2013
    Location
    Austin, Texas, USA
    MS-Off Ver
    Excel 2007 Home
    Posts
    17

    Lightbulb Boolean Values in IF Statements

    I have seen several people submit solutions to problems that include formulas like, for example,

    Please Login or Register  to view this content.
    The syntax is not wrong, but since an IF statement is looking for a TRUE or FALSE, I entered the following, and it works just fine...

    Please Login or Register  to view this content.
    I found that it works in macros, too. I used the following this week, and it works exactly as I expected...

    Please Login or Register  to view this content.
    This one works great, too:

    Please Login or Register  to view this content.

  2. #2
    @dministrator JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    33,062

    Re: Boolean Values in IF Statements

    Even simpler still:

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  3. #3
    Forum Guru Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,891

    Re: Boolean Values in IF Statements

    Quote Originally Posted by HankW501 View Post
    The syntax is not wrong, but since an IF statement is looking for a TRUE or FALSE, I entered the following, and it works just fine...

    =IF($Y$32, 1, 0)
    Yes, it will work on numbers and Boolean values.

    Any number other than 0 evaluates to TRUE and 0 evaluates to FALSE.

    A text value will generate the #VALUE! error:

    =IF("x",1,0) = #VALUE!
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Registered User
    Join Date
    09-16-2013
    Location
    Austin, Texas, USA
    MS-Off Ver
    Excel 2007 Home
    Posts
    17

    Re: Boolean Values in IF Statements

    =--$Y$32
    What does that do?

  5. #5
    @dministrator JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    33,062

    Re: Boolean Values in IF Statements

    Quote Originally Posted by HankW501 View Post
    What does that do?
    Ha, I believe that falls into the category of "did you try it and see what it does"?

    The -- is called a double unary and in this instance it coerces a 1 or 0 from TRUE or FALSE.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1