+ Reply to Thread
Results 1 to 11 of 11

Nested, IF, AND, and OR function

  1. #1
    Registered User
    Join Date
    02-15-2009
    Location
    Michigan, USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Nested, IF, AND, and OR function

    I have an assignment in which I have to use nested, IF, AND and OR functions. Does anyone know the syntax for this kind of function? Basically I have to determine leave time based on years of service and whether the employee is full time or part time. Part-time with less than 1.5 years of service = 0 days of leave Part-time over 1.5 and full-time under 1year = 3 days of leave and full time over 1 year = 5 days of leave. I know how to do a nested function, but I have not worked with both an AND and OR together.

    Thanks in advance!!!

    Thanks Agoin
    Last edited by VBA Noob; 02-23-2009 at 05:04 AM.

  2. #2
    Forum Contributor mewingkitty's Avatar
    Join Date
    09-29-2008
    Location
    Fort McMurray, Alberta, Canada
    MS-Off Ver
    Excel 2003
    Posts
    949

    Re: Nested, IF, AND, and OR function

    Sure I'll throw together some examples of how they work, but since it's an assignment, I can't really just write it for ya, gimme a min and I'll put up some examples in a sheet.
    =IF(AND(OR(BLONDE,BRUNETTE,REDHEAD),OR(MY PLACE,HER PLACE),ME),BOW-CHICKA-BOW-WOW,ANOTHER NIGHT ON THE INTERNET)

  3. #3
    Registered User
    Join Date
    02-15-2009
    Location
    Michigan, USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Nested, IF, AND, and OR function

    I appreciate the help, I have been trying to figure it out for over an hour, and I just can't quite get it right. An example would be wonderful!!!!

  4. #4
    Forum Contributor mewingkitty's Avatar
    Join Date
    09-29-2008
    Location
    Fort McMurray, Alberta, Canada
    MS-Off Ver
    Excel 2003
    Posts
    949

    Re: Nested, IF, AND, and OR function

    See attached.
    I'll be on for a while if you need further clarification, my messenger info is on here too.

    mew!

    EDIT:
    Although not functional for obvious lack of quotation marks and non-existent references, my signature is also a good example of a nested IF, AND, OR statement, albeit a humorous one.
    Last edited by mewingkitty; 03-13-2009 at 06:45 PM.

  5. #5
    Registered User
    Join Date
    02-15-2009
    Location
    Michigan, USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Nested, IF, AND, and OR function

    If the instructor had shown us an example, OR explained it better AND showed an example, I wouldn't be having this problem.

  6. #6
    Forum Contributor mewingkitty's Avatar
    Join Date
    09-29-2008
    Location
    Fort McMurray, Alberta, Canada
    MS-Off Ver
    Excel 2003
    Posts
    949

    Re: Nested, IF, AND, and OR function

    Hee hee hee

    Did that example help?

  7. #7
    Registered User
    Join Date
    02-15-2009
    Location
    Michigan, USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Nested, IF, AND, and OR function

    I am still stuck,
    =IF(AND(OR(b6="PT",d6<1.5),0,if(d6>1.5,3,OR(b6="FT",ANDd6<1,3)))),5
    I can not figure out what I am doing wrong.

  8. #8
    Forum Contributor mewingkitty's Avatar
    Join Date
    09-29-2008
    Location
    Fort McMurray, Alberta, Canada
    MS-Off Ver
    Excel 2003
    Posts
    949

    Re: Nested, IF, AND, and OR function

    =IF(AND(OR(b6="PT",d6<1.5),0,
    this first part of your statement, should read:
    =IF(AND(B6="PT",D6<1.5),0,"other conditions")

    If it were to stand alone, and only look for "PT" AND D6<1.5

    if(d6>1.5,3,OR(b6="FT",ANDd6<1,3)))),5
    this second part, you're getting ahead of yourself and tripping up on the syntax.

    If statements have a criteria, a result if true, then result if false.
    so IF(A1=1,1,2) would return 1 if A1=1, and 2 if A1=anything but 1
    That structure is what you need to keep track of, and what makes IF statements hard to understand at first, especially when you throw in ANDs.

    IF(AND(A1=1,A2=2),1,2)

    would function as follows.
    IF A1 = 1 AND A2 = 2, THEN 1
    ELSE 2

    I don't want to just throw the answer at you, because if you need to understand it, and I just give it to you, you're not really any farther ahead.

  9. #9
    Registered User
    Join Date
    02-15-2009
    Location
    Michigan, USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Nested, IF, AND, and OR function

    I finally got it. And that was before I saw your post.

    =IF(AND(b6="FT",d6>1,5,IF(OR(b6="PT",d6>1),3,0))

    Thanks for your help, I kept looking at the blonde in your house, and I finally figured it out.

  10. #10
    Forum Contributor mewingkitty's Avatar
    Join Date
    09-29-2008
    Location
    Fort McMurray, Alberta, Canada
    MS-Off Ver
    Excel 2003
    Posts
    949

    Re: Nested, IF, AND, and OR function

    =IF(AND(b6="FT",d6>1),5,IF(OR(b6="PT",d6>1),3,0))

    This says that if b6 = FT and D6 > 1, then 5
    else
    If b6 = PT OR D6 > 1 then 3
    else
    0

    I'm not sure that's exactly what you wanted...
    Correction, I'm sure that's not what you wanted.

    As per my signature, it reads
    If there's a blonde, or redhead, or brunette
    and
    my place, or her place
    and
    me
    then
    bow chicka bow wow
    else
    another night on the internet.

    As per your code, since you've already put quite a few hours in, and it sounds like you think you got it figured, what I believe you actually need is:
    Please Login or Register  to view this content.
    If B6 = PT and D6 < 1.5, then 0
    else
    if B6 = PT and D6 >= 1.5 - OR - if B6 = FT and D6 < 1 then 3
    else
    if B6 = FT and D6 >=1 then 5
    else
    0


    The <= are actually somewhat important, since if someone has exactly 1.5, or 3, and you only include < and > as criteria, your formula will not function.

    It's very good practice to test your code under all conditions before approving it for use. Yours will return 3 if B6 is "PT" and D6 is 0, which is not correct.

    Hope ya see this before you turn that assignment in.

    mew!
    Last edited by mewingkitty; 02-23-2009 at 02:02 AM.

  11. #11
    Registered User
    Join Date
    02-15-2009
    Location
    Michigan, USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Nested, IF, AND, and OR function

    Thank you so much for your help, you were right I was missing some data.

+ 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