+ 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
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    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 Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    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
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    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)

Similar Threads

  1. Data validation on list of boolean values
    By 1eyedjack in forum Excel General
    Replies: 2
    Last Post: 08-19-2018, 06:03 PM
  2. [SOLVED] Countifs with Boolean Values given by sets of conditions
    By NunoE in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 11-05-2014, 09:14 AM
  3. Boolean values in charts
    By general_belgrano in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 06-13-2013, 10:35 AM
  4. Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) problem
    By 2funny4words in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-29-2009, 07:28 PM
  5. Comparing text and returning boolean values
    By nicoleeee in forum Excel General
    Replies: 9
    Last Post: 12-02-2005, 06:43 AM

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