+ Reply to Thread
Results 1 to 11 of 11

Boolean operator within excel function

  1. #1
    Registered User
    Join Date
    06-11-2015
    Location
    Ohio
    MS-Off Ver
    2010
    Posts
    5

    Boolean operator within excel function

    I am not new to excel or vba; however, I am having some difficulty with the lack of a boolean "or" function in excel. As you know, the "&" function works fine, but you cannot insert the "|" or "||" operator into a formula. Is there an alternative that will give me an "or"?

    Note: The pre-defined "or function" (i.e., [or(condition1, condition 2...)] is not helpful in this instance. It evaluates values in another set of cells rather than the current cell and returns "true" or "false" instead of a numeric value.

    The code that I am currently using is the following: =IF(IFERROR(INDEX($H$2:INDIRECT("H"&ROW()-1),MATCH(7,$D$2:INDIRECT("D"&ROW()-1),0)),0)=99,(INDIRECT("F"&ROW())*2),INDIRECT("F"&ROW()))

    The value "7" is currently being matched. I need it to match multiple values, such as Match(5|6|7,... or Match (5||6||7,...

    Any bright ideas?


    microsoft-excel
    shareeditflag

    asked 1 min ago
    Noah
    1

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Boolean operator within excel function

    Please Login or Register  to view this content.
    https://www.google.com/webhp?sourcei...20or%20formula
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Registered User
    Join Date
    06-11-2015
    Location
    Ohio
    MS-Off Ver
    2010
    Posts
    5

    Re: Boolean operator within excel function

    As I mentioned in my thread, that is not appropriate to this task. It requires a conditional value from another cell and returns only a true or false rather than a number.

  4. #4
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Boolean operator within excel function

    Before diving into this...
    Can you confirm that the formula you posted actually provides the desired results based on 7 in the match?

    And just to make this easier, lets take the indirect out of it. Much easier to read.
    Assuming the formula is entered in say row 21, so ROW()=21
    That formula would translate to

    =IF(IFERROR(INDEX($H$2:$H$20,MATCH(7,$D$2:$D$20,0)),0)=99,(F21*2),F21)

    And what you want is to do the INDEX with 5, 6, and 7 in the Match, and if any of them = 99 then... etc.
    sort of like
    If INDEX($H$2:$H$20,MATCH(5,$D$2:$D$20,0)),0)=99 OR INDEX($H$2:$H$20,MATCH(6,$D$2:$D$20,0)),0)=99 OR INDEX($H$2:$H$20,MATCH(7,$D$2:$D$20,0)),0)=99 Then...

    Is that about right?

  5. #5
    Registered User
    Join Date
    06-11-2015
    Location
    Ohio
    MS-Off Ver
    2010
    Posts
    5

    Re: Boolean operator within excel function

    Yes, that is a long way of doing it, but that is exactly what I want it to do. Will the OR function work like that? I will give it a shot and see.

  6. #6
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Boolean operator within excel function

    No, you're right the OR won't work for this.

    Try
    =IF(SUM(COUNTIFS($D$2:$D$20,{5,6,7},$H$2:$H$20,99)),F21*2,F21)

    I'll leave it to you to put the indirect back into it.

  7. #7
    Registered User
    Join Date
    06-11-2015
    Location
    Ohio
    MS-Off Ver
    2010
    Posts
    5

    Re: Boolean operator within excel function

    Yes, that is a long way of doing it, but that is exactly what I want it to do. Will the OR function work like that? I will give it a shot and see.

    >>I just tried that and again, OR is looking for conditional values in a specified other location and wants to spit out trues and falses.

  8. #8
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Boolean operator within excel function

    Or even

    =IF(COUNTIFS($D$2:$D$20,">=5",$D$2:$D$20,"<=7",$H$2:$H$20,99),F21*2,F21)

  9. #9
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Boolean operator within excel function

    You can save yourself 1 indirect reference by doing it this way

    Instead of
    =IF(SUM(COUNTIFS($D$2:$D$20,{5,6,7},$H$2:$H$20,99)),F21*2,F21)

    Do
    =((SUM(COUNTIFS($D$2:$D$20,{5,6,7},$H$2:$H$20,99))>0)+1)*F21

  10. #10
    Registered User
    Join Date
    06-11-2015
    Location
    Ohio
    MS-Off Ver
    2010
    Posts
    5

    Re: Boolean operator within excel function

    It works perfectly! You are a genius! (although you probably already know that )

  11. #11
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Boolean operator within excel function

    You're welcome.

+ 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. Help Returning A Function Boolean
    By viruzman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-12-2012, 10:52 AM
  2. 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

Tags for this Thread

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