+ Reply to Thread
Results 1 to 6 of 6

Convert Boolean to 0/1

  1. #1
    Registered User
    Join Date
    03-04-2008
    Posts
    60

    Convert Boolean to 0/1

    I have a function with a boolean argument and im passing AND(condition1, condition2) and the result of that im returning with some other stuff but I need to output either 0 or 1 for false/true. Using Format() it gives me 0 and -1 which is not what I want

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Not exactly sure what you mean, but =AND(cond1, cond2, ..., condN) * 1 wiill return a 1 or 0.

  3. #3
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Convert Boolean to 0/1

    Try this:

    ABS(your_expression)

    That will convert -1 to 1
    ..0 will remain 0

    Does that help?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  4. #4
    Registered User
    Join Date
    03-04-2008
    Posts
    60
    wow i didn't even think of Abs (smack to forhead) thanks

  5. #5
    Registered User
    Join Date
    08-12-2005
    Posts
    33
    Quote Originally Posted by slide
    I have a function with a boolean argument and im passing AND(condition1, condition2) and the result of that im returning with some other stuff but I need to output either 0 or 1 for false/true. Using Format() it gives me 0 and -1 which is not what I want
    For converting boolean arguments (True or False) to 1 or 0 .

    If A1 cell housesTrue or False argument. Then we can use like these:

    =--(A1)
    =(A1)*1
    =1*(A1)
    =(A1)/1
    =(A1)+0
    =0+(A1)
    =(A1)-0
    =(A1)^1
    =ABS(A1)


    ..

  6. #6
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    You're welcome!

    I'm glad that helped.

+ 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