+ Reply to Thread
Results 1 to 16 of 16

Nested if statement

  1. #1
    Forum Contributor
    Join Date
    01-18-2010
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    128

    Nested if statement

    If age is between 30 -39, put $162.40; if age is between 50 - 54, put $293.60,etc,etc

    Thank you, gurus!

  2. #2
    Valued Forum Contributor
    Join Date
    03-14-2012
    Location
    Arizona USA
    MS-Off Ver
    Excel 2000/2007
    Posts
    408

    Re: Nested if statement

    The worksheet function would look like this;

    Please Login or Register  to view this content.
    In my opinion, many people get carried away with long worksheet functions. They get difficult to read and manage.

    Any larger than this one and I would make a custom worksheet function that looks like =Age2Value(A1).
    Last edited by Dennis7849; 03-27-2012 at 03:32 PM.

  3. #3
    Registered User
    Join Date
    03-25-2012
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Nested if statement

    You can use something like this.

    =IF(AND(A1>" ",A3<40),"$162.40",IF(AND(A1>" ",A3<55),"293.60",IF(AND(A1>" ",A3<60),"$400.00"," ")))

    This assumes you have data to enter in cell A1, for example, the person's name. And in cell A3 you enter their age. Of course A1 can be filled with anything really. the formula only requires something other than a blank be there. And this formula would go in a cell other than A1 or A3. Hope that helps.

    Alfred-

  4. #4
    Forum Contributor
    Join Date
    08-04-2011
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2007
    Posts
    109

    Re: Nested if statement

    It is not necessary to use an "AND" statement if you start with the smallest number and work your way up or start with the largest and work your way down as follows:
    =if(A1<30,150,if(A1<40,162.40,if(A1<55,293.60, if(A1<...

  5. #5
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Nested if statement

    You can also skip the nested IF's and just use a LOOKUP in ascending order, e.g.

    =LOOKUP(A1,{30,40,50,60},{162.40,192.80,223.20,253.60})

    The first array needs to be in ascending order, the second simply correlates to that (could be in descending if your $ amounts went down with age, for example).

  6. #6
    Forum Contributor
    Join Date
    01-18-2010
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    128

    Re: Nested if statement

    This works beautifully. Thank you very much!

  7. #7
    Forum Contributor
    Join Date
    01-18-2010
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    128

    Re: Nested if statement

    Thank you very much. As Dyonisos said, the AND was not necessary though.

  8. #8
    Forum Contributor
    Join Date
    01-18-2010
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    128

    Re: Nested if statement

    I am going to be cheeky and ask a continuation of this if statemment with one more condition: andif M2 has a number in it (any number), then.... How do I connect this to the previous series of if statements? Thanks very much for the help.

  9. #9
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Nested if statement

    So if M2 doesn't have a number, don't do the calculation at all? In that case..

    =IF(ISNUMBER(M2),LOOKUP(A1,{1,2,3,4},{3.3,4.4,2.2,6.6}),"")

  10. #10
    Forum Contributor
    Join Date
    08-04-2011
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2007
    Posts
    109

    Re: Nested if statement

    =if(ISNUMBER(m2)=true,[nested if statements],"")

  11. #11
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Nested if statement

    No need for the "=true" bit, as ISNUMBER() will return TRUE or FALSE and that will be used to determine which argument in the IF statement is acted upon.

  12. #12
    Forum Contributor
    Join Date
    08-04-2011
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2007
    Posts
    109

    Re: Nested if statement

    Thanks Paul!

  13. #13
    Forum Contributor
    Join Date
    01-18-2010
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    128

    Re: Nested if statement

    You, Guys are too smart, but I am not. I tried to connect the isnumber and if, but I did something wrong because it didn't work.
    =IF(ISNUMBER(S2),(E2<30,137.5,IF(E2<=39,162.4,IF(E2<=49,220,IF(E2<=54,293.6,IF(E2<=59,364.8,IF(E2<=64,468,IF(E2>=65,567.2))))))),"")
    Probably don't know how to place my parenthesis.

  14. #14
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Nested if statement

    Any reason why you'd want to continue using nested IF statements when the LOOKUP function is cleaner? Even if you did stick with that, you need to included the IF after the ISNUMBER argument.

    =IF(ISNUMBER(S2),LOOKUP(E2,{0,30,40,50,55,60,65},{137.5,162.4,220,293.6,364.8,468,567.2}),"")

  15. #15
    Forum Contributor
    Join Date
    01-18-2010
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    128

    Re: Nested if statement

    Because what could I say? That I like suffering? :D Thank you very much! It works great.

  16. #16
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Nested if statement

    Glad it works.

    If you're satisfied that your problem is resolved, please do mark the thread as Solved. To do so, in your first post in the thread click 'Thread Tools' (just above the post) and then 'Mark this thread as solved'.

    Thanks!

+ 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