+ Reply to Thread
Results 1 to 28 of 28

Nested IF Functions

  1. #1
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Norfolk UK
    MS-Off Ver
    2007
    Posts
    222

    Nested IF Functions

    Hi Guys

    not sure if I can reopen a query, he goes

    Jb helped with the info I gave him or did not, now I have added another section in sheet 5

    Help JB

    Stephen
    Attached Files Attached Files
    Last edited by stephen1000; 12-17-2008 at 06:34 PM. Reason: added more data

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

    My convoluted system

    I see some if functions here and there, but without knowing which ones you want to have precedence I can't really put them together for you.

    Anytime I need to put together a large group of "if"s, I do them one at a time, a-like-a-so
    Please Login or Register  to view this content.
    That way you can test each section while still only changing your initial data, also works if they're dependant upon eachother ( The code would simply refer to the cell above it for it's criteria ). When you want to conglomerate them all, start at the bottom, (I'd recommend making a copy of them while seperated for future use), anyways, start at the bottom, and work your way up, replacing "Next step" with the formula from the line below it, without the = of course ( If the cells are dependant upon eachother, you'd replace any part of the code which had say.. A2, with the formula in A2) . Add one more bracket on the end for each IF you add, and there you have it - An insanely complex if statement which is completely indicipherable. But functional.

    p.s.
    I'd REALLY recommend keeping a copy of the broken down versions for future use, saves a lot of trouble if criteria changes.
    Last edited by mewingkitty; 12-10-2008 at 06:02 PM. Reason: Cuz I luvz editz!

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    You can nest 7 if statements together. To go beyond that would require you use a second column to do some followup. 14 IFs would probably take 3 cells.

    Are you sure you even need IF? It appears you're looping the same formula over and over looking for a value, and that is what LOOKUP is best suited for.

    I added some range markers at the top of sheet5 in green, and changed the formulas on Sheet4 to show how a much shorter LOOKUP gets you the same result (green cells).

    Is that cell N14 the one that was giving you problems? It works now.
    Attached Files Attached Files
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Norfolk UK
    MS-Off Ver
    2007
    Posts
    222

    Cool

    Quote Originally Posted by JBeaucaire View Post
    You can nest 7 if statements together. To go beyond that would require you use a second column to do some followup. 14 IFs would probably take 3 cells.

    Are you sure you even need IF? It appears you're looping the same formula over and over looking for a value, and that is what LOOKUP is best suited for.

    I added some range markers at the top of sheet5 in green, and changed the formulas on Sheet4 to show how a much shorter LOOKUP gets you the same result (green cells).

    Is that cell N14 the one that was giving you problems? It works now.
    Hi
    E2 is the entry point, N7:N14 pulls the data from sheet 5 depending on the entry in E2 ie 1200

    it looks up the corresponding values upto that size and equaling it and fills the data .

    does that make sense

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    Please download and review the sheet I posted above. The green cells on sheets 4 & 5 are my edits. I think this is all you need, to stop using IF and use LOOKUP instead.

  6. #6
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Norfolk UK
    MS-Off Ver
    2007
    Posts
    222
    Quote Originally Posted by JBeaucaire View Post
    Please download and review the sheet I posted above. The green cells on sheets 4 & 5 are my edits. I think this is all you need, to stop using IF and use LOOKUP instead.
    I have, but it does not return the data it should

    sorry

  7. #7
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Norfolk UK
    MS-Off Ver
    2007
    Posts
    222
    N7 should read 1
    n8 should read 7
    N9 should read 7
    N10 should read 7
    N11 should read 5
    N12 should read 5
    N13 should read 2
    N14 should read 2

    pasted yellow sheet 4, sheet 5

    thanks

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    I created a LOOKUP designed to replicate the answers you showed in your first post. Were those answers wrong? You didn't say that...

    What value in E2 was generating these answers? 1 7 7 7 5 5 2 2 ?

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    OK, I realized your cell D5 was critical, too. So I built in a check into the formulas in N7-N14 to watch that cell, too.

    When I parse out the value in E2, it's equivalent to column F on Sheet5, right? In that case, based on the choice in D5, the data in green now flows from column F for that value.

    I added the missing 2320 chart at the bottom of Sheet5 and it needs your actual part # and values in the chart. (yellow cells) But the sheet4 green cells are watching that part already, so they'll work once you put those values in.
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Norfolk UK
    MS-Off Ver
    2007
    Posts
    222
    Quote Originally Posted by JBeaucaire View Post
    OK, I realized your cell D5 was critical, too. So I built in a check into the formulas in N7-N14 to watch that cell, too.

    When I parse out the value in E2, it's equivalent to column F on Sheet5, right? In that case, based on the choice in D5, the data in green now flows from column F for that value.

    I added the missing 2320 chart at the bottom of Sheet5 and it needs your actual part # and values in the chart. (yellow cells) But the sheet4 green cells are watching that part already, so they'll work once you put those values in.

    Thanks JB
    I get it, but not really


    I have another one posted over on the Excel charts section, involving a drop down list of 43 staff, and data being pulled from another sheet depending on the name chosen then charted out for performance.

    stephen

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    Be sure to EDIT your original post and mark the PREFIX box [SOLVED]

  12. #12
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Norfolk UK
    MS-Off Ver
    2007
    Posts
    222
    Hi JB help if you can or want too


    cheers

    stephen

    look at the attachment on the first post

    cheers

  13. #13
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    Did you just ask a question I missed? I thought this thread was solved.

  14. #14
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Norfolk UK
    MS-Off Ver
    2007
    Posts
    222
    Hi JB,

    I thought it was, I am adding more data to sheet 5 ie 2020, 2120, 2320 & batten; following what formulas you have added but it wont let me add any more ie Batten.

    would appriciate your help

    cheers

    stephen

  15. #15
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    How many more? Any chance you can lay that out completely before submitting it for any more help? Add all the sections you want, then post it up again.

  16. #16
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Norfolk UK
    MS-Off Ver
    2007
    Posts
    222
    Hi Jb

    thanks will do.

    stephen

  17. #17
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Norfolk UK
    MS-Off Ver
    2007
    Posts
    222

    Smile

    Hi JB

    attached is the continuing worksheet you have helped so much on

    cheers

    page 5 has the info

    when hardware is choosen "Batten", like the others the relavent info needs to come up


    stephen
    Attached Files Attached Files

  18. #18
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    Here you go.

    I made the formulas a little easier to read in the cells, so you can decipher it more readily if you want to add another level. You can go 3 more, then you need a new design since IF only goes 7 deep in Excel 2003.
    Attached Files Attached Files

  19. #19
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Norfolk UK
    MS-Off Ver
    2007
    Posts
    222

    Smile

    Quote Originally Posted by JBeaucaire View Post
    Here you go.

    I made the formulas a little easier to read in the cells, so you can decipher it more readily if you want to add another level. You can go 3 more, then you need a new design since IF only goes 7 deep in Excel 2003.
    Hi JB

    Thanks for that,

    I will try to understand more by looking through the formulas

    cheers

  20. #20
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    It was really bugging me bumping up into those IF limitations, so here is your sheet without IF usage, changing over to an Indexed TABLE (name range). To make it work simply, I used an added column on Sheet5 to make a single lookup range from the small table and sub item, you'll see what I mean when you look at column A.

    When you expand your tables to include more sections, just make sure those helper cells are included and your Sheet4 Index/Match formulas will just keep plugging along.

    Cheers.
    Attached Files Attached Files

  21. #21
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Norfolk UK
    MS-Off Ver
    2007
    Posts
    222

    Smile

    Hi JB

    Thats awesome man,

    now it only shows 2020 upto 2500 anything over that then the next system is used 2120 or 2320

    one small problem when batten is selected, N22 should show calculations going down the page, the formulas are their but no results

    thanks again for what you have done, when this is implemented the time and cost saving should earn me a pat on the back

    cheers

  22. #22
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Norfolk UK
    MS-Off Ver
    2007
    Posts
    222
    Hey JB

    Fixed it, too much vino I think.

    I think i will mark this thread Solved

    Thanks again


  23. #23
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Norfolk UK
    MS-Off Ver
    2007
    Posts
    222
    BL*********dy pc crashed

    Anyway

    JB you are a star

    Off now to watch telly and finish the red off

    speak again take care

  24. #24
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    I noticed you had triggered M22 with a reference that didn't take into account that Batten figures started at 1, and that makes 1-1=0, so the cell stayed blank.

    Take care.
    Last edited by JBeaucaire; 12-17-2008 at 12:17 AM.

  25. #25
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Norfolk UK
    MS-Off Ver
    2007
    Posts
    222

    Smile

    Hi JB,

    I was out all day today, looking over what you have done, I have noticed that if the value entered in E2 is less than 1500 N/A appears on page 2 all the way down the list of parts?

    I have had a look and cannot figure out why.

    any chance you can look at it for me

    cheers

    ps i see where you are having to *0.001; I have changed vaule's too MM now
    this is not the reason for the N/a I started checking this with the 1.75 etc on sheet 5

    Attached Files Attached Files

  26. #26
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    Well, built into LOOKUP is the ability to drop down to the next lowest value in a table and still keep working. That's why it was fine in earlier versions.

    INDEX/MATCH is an exact science. Sorry, I forgot that. I added in a FLOOR() formula to force the E2 calculation to drop down to the next 250 mark, which is what you've changed your chart to use for breakpoints on Sheet5.

    I added in some fun conditional formatting, too, in the bottom right section.

    I love Excel.
    Attached Files Attached Files

  27. #27
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Norfolk UK
    MS-Off Ver
    2007
    Posts
    222
    Hi JB

    checking now looks good

    cheers mate

  28. #28
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Norfolk UK
    MS-Off Ver
    2007
    Posts
    222

    Smile

    Hi JB

    I have checked through looks great, seen what you have done with the formating; did on page one sheet 4


    thank you for all your help.

    will mark as solved later

    take care

    stephen
    Attached Files Attached Files

+ 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