+ Reply to Thread
Results 1 to 7 of 7

Nested if statement help

  1. #1
    Registered User
    Join Date
    09-01-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    6

    Nested if statement help

    So I'm trying to assign a class to an animal for a livestock show based on animals date of birth. I am able to get a single IF statement to work, but not able to get the conditions for all the possible classes. This is the statement I have that works:
    =IF(AND(D2>Classes!$B$3,D2<Classes!$C$3),2)

    What I need is:
    =IF(AND(D2>Classes!$B$2,D2<Classes!$C$2),1)
    =IF(AND(D2>Classes!$B$3,D2<Classes!$C$3),2)
    =IF(AND(D2>Classes!$B$4,D2<Classes!$C$4),3)
    =IF(AND(D2>Classes!$B$5,D2<Classes!$C$5),4)
    =IF(AND(D2>Classes!$B$6,D2<Classes!$C$6),5)
    =IF(AND(D2>Classes!$B$7,D2<Classes!$C$7),6)
    =IF(AND(D2>Classes!$B$8,D2<Classes!$C$8),7)

    So if I enter a date it will automatically populate the Class field as Class 1 - Class 7.

    Thanks in advance,
    Aaron

  2. #2
    Registered User
    Join Date
    09-01-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Nested if statement help

    Still a novice at most excel things, but without seeing your actual workbook to know if it works and what references what, you could try this. No guarantees.

    =IF(AND(D2>Classes!$B$2,D2<Classes!$C$2),1,IF(AND(D2>Classes!$B$3,D2<Classes!$C$3),2,IF(AND(D2>Classes!$B$4,D2<Classes!$C$4),4,IF(AND(D2>Classes!$B$5,D2<Classes!$C$5),4,IF(AND(D2>Classes!$B$6,D2<Classes!$C$6),5,IF(AND(D2>Classes!$B$7,D2<Classes!$C$7),6,IF(AND(D2>Classes!$B$8,D2<Classes!$C$8),7,"No_Class")))))))

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Nested if statement help

    Hi and welcome to the forum

    2 suggestions come to mind....
    1. string the formulas together, something like,,,
    =IF(AND(D2>Classes!$B$2,D2<Classes!$C$2),1,IF(AND(D2>Classes!$B$3,D2<Classes!$C$3),2),IF(AND(D2>Classes!$B$4,D2<Classes!$C$4),3)….)

    OR
    2. leave them like that - put them somewhere out of the way, and then use =max() to return the value.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Forum Contributor
    Join Date
    08-14-2013
    Location
    Florida
    MS-Off Ver
    Excel 2013
    Posts
    105

    Re: Nested if statement help

    Yes an example worksheet showing the dates and some expected results would help.

  5. #5
    Registered User
    Join Date
    09-01-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Nested if statement help

    showbreaker.xlsx

    Worked like a champ...I tried something similar but could never seem to get it to work....Thanks much..Attached is workbook with your fix..
    Last edited by acmumph; 09-01-2013 at 03:49 PM.

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Nested if statement help

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a relatively new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  7. #7
    Forum Contributor
    Join Date
    08-14-2013
    Location
    Florida
    MS-Off Ver
    Excel 2013
    Posts
    105

    Re: Nested if statement help

    Can try this;

    I just learned this one... took me a bit to get it right. If you want to change Class from numbers, to anything... Say Fat Cow, Skinny Cow, Young Cow, Old Cow... just change the data in column D.

    =LOOKUP(2,1/--((B2:B8<E2)--(E2>C2:C8)),D2:D8)
    Attached Files Attached Files
    Last edited by Kalithro; 09-01-2013 at 04:24 PM.

+ 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. [SOLVED] Nested If Statement - ISBLANK and ISNA in same statement?
    By Janc in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 04-23-2013, 09:00 AM
  2. [SOLVED] Nested IF Statement Help Pls
    By gautamacharya in forum Excel General
    Replies: 2
    Last Post: 06-28-2012, 12:58 PM
  3. Nested if statement
    By Orionfi in forum Excel General
    Replies: 8
    Last Post: 02-15-2012, 10:52 PM
  4. Nested IF statement with OR & AND
    By concatch in forum Excel General
    Replies: 4
    Last Post: 02-07-2012, 08:55 AM
  5. Replies: 6
    Last Post: 01-14-2009, 06:59 PM

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