+ Reply to Thread
Results 1 to 11 of 11

Complicated Nested IF with OR & AND

  1. #1
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Cape Town
    MS-Off Ver
    Excel 2010
    Posts
    107

    Complicated Nested IF with OR & AND

    IF (
    (CF2 = LONDON OR CF2 = PARIS OR CF2 = WASHINGTON DC) AND (CG2 = Wednesday) AND (CH2 = 19 OR CH2 = 20 OR CH2 = 21 OR CH2 = 22 OR CH2 = 23 OR CH2 = 0 OR CH2 = 1 OR CH2 = 2 OR CH2 = 2)
    OR
    (CF2 = ATHENS OR CF2 = ATLANTA OR CF2 = ROME) AND (CG2 = Thursday) AND (CH2 = 19 OR CH2 = 20 OR CH2 = 21 OR CH2 = 22 OR CH2 = 23 OR CH2 = 0 OR CH2 = 1 OR CH2 = 2 OR CH2 = 2)
    ) THEN Y ELSE N

    So basically it's the first condition OR the second condition then return Y else N
    Last edited by concatch; 02-07-2012 at 09:43 AM.

  2. #2
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Complicated Nested IF with OR & AND

    =IF(OR(AND(OR(CF2={"LONDON","PARIS","WASHINGTON DC"}),CG2="Wednesday",OR(CH2={0,1,2,19,20,21,22,23})),AND(OR(CF2={"ATHENS","ATLANTA","ROME"}),CG2="Thursday",OR(CH2={0,1,2,19,20,21,22,23}))),"Y","N")

    I think. You could also simplify the CH2 part as it is the same for both.
    Good luck.

  3. #3
    Forum Expert
    Join Date
    12-03-2009
    Location
    Florence, Italy
    MS-Off Ver
    Excel 2019
    Posts
    1,796

    Re: Complicated Nested IF with OR & AND

    Hi

    maybe

    Please Login or Register  to view this content.
    To be doublechecked

    Regards
    Last edited by canapone; 02-07-2012 at 09:24 AM.
    -----------------------------------------------------

    At Excelforum, you can say "Thank you!" by clicking the star icon ("Add Reputation") below the post.

    Please, mark your thread [SOLVED] if you received your answer.

  4. #4
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Complicated Nested IF with OR & AND

    Hi

    Something like this, maybe??


    =IF(OR(AND(OR(CF2="LONDON",CF2="PARIS",CF2="WASHINGTON" ),CG2="Wednesday",OR(CH2=19,CH2=20,CH2=21,CH2=22,CH2=23,CH2=0,CH2=1,CH2=2,CH2= 2)),AND(O(CF2="ATHENS",CF2="ATLANTA",CF2= "ROME" ),CG2="Thursday",OR(CH2=19,CH2=20,CH2=21,CH2=22,CH2=23,CH2=0,CH2=1,CH2=2,CH2=2))),"Y","N")

    Hope to helps you.


    Note: CANAPONE: Same formula. Sorry!
    Last edited by Fotis1991; 02-07-2012 at 09:27 AM. Reason: Note
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  5. #5
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Complicated Nested IF with OR & AND

    Simplified version of my previous

    =IF(AND(OR(CH2={0,1,2,19,20,21,22,23}),OR(AND(OR(CF2={"LONDON","PARIS","WASHINGTON DC"}),CG2="Wednesday"),AND(OR(CF2={"ATHENS","ATLANTA","ROME"}),CG2="Thursday"))),"Y","N")

  6. #6
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Cape Town
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: Complicated Nested IF with OR & AND

    Thanks everyone!!! Solutions work well

    OnErrorGoto0 Your solution is elegant and I learned something new, how to reference arrays with {} which is very useful!

    Thanks again!!!

  7. #7
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,675

    Re: Complicated Nested IF with OR & AND

    So complicated with AND(OR(AND...
    Also try to avoid sth repeat twice or more...
    Try to figure it out in simplest way:
    IF numberlist, then IF Wednesday, then IF Thusday, else

    =IF(CH2<>{0,1,2,19,20,21,22,23},"N",IF(CG2="Wednesday",IF(OR(CF2={"LONDON","PARIS","WASHINGTON DC"}),"Y","N"),IF(CG2="Thursday",IF(OR(CF2={"ATHENS","ATLANTA","ROME"}),"Y","N"),"N")))
    Quang PT

  8. #8
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Complicated Nested IF with OR & AND

    @bebo021999
    Ignoring for a moment the fact that your formula doesn't work as posted, how is it really simpler than what I suggested?

  9. #9
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,675

    Re: Complicated Nested IF with OR & AND

    @OEG0,
    Would you mind to show me the incorrect case?
    Nice to learn from you.

  10. #10
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Complicated Nested IF with OR & AND

    Try using London, Wednesday and 1 (or indeed any valid number other than 0) and it will return N, not Y.

  11. #11
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,675

    Re: Complicated Nested IF with OR & AND

    Oh Oh, it's my faul. Forgot that =IF(CH2<>{0,1,2,19,20,21,22,23},... always returns 0 if false
    may replaced by: = IF(ISERROR(MATCH(CH2,{0,1,2,19,20,21,22,23},0)),...
    By this, a litle bit longer.

    Tks a lot,

+ 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