Consulting

Results 1 to 9 of 9

Thread: Solved: More than 7 Nested IF's

  1. #1
    VBAX Regular
    Joined
    Feb 2011
    Posts
    20
    Location

    Solved: More than 7 Nested IF's

    I've been trying to figure out a way to add another IF in the below formula but can't wrap my head around the impact of the variable cell, F41 in this case, then would go down one row to F42, F43, etc...

    I've read up on putting it to VBA or using Named Ranges but the variable cells throw me off.

    =IF(F41="","",IF(F41=$AE$27,MAX(H41,$V$13*I41),IF(F41=$AE$28,MAX(MAX(,$V$13 ,$B$22*E41,$D$14)*I41,H41),IF(F41="Container",H41*I41,IF(F41="flat",H41,IF( F41="CBM",MAX(MAX($V$13/E41,$B$22)*I41,H41),MAX(MAX($V$13,$B$22*E41)*I41,H41,$D$22)))))))

    any ideas? the first IF F41="" is important for esthetics purposes

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Can you post a workbook with sample data to test solutions?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    Feb 2011
    Posts
    20
    Location

    Nested IF's

    Here you go, hope this works
    Last edited by PEV; 02-21-2012 at 11:56 AM.

  4. #4
    VBAX Regular
    Joined
    Feb 2011
    Posts
    20
    Location

    sorry, wrong file

    sorry, new file.
    Attached Files Attached Files

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try this

    =IF(F30="","",IF(F30=$AE$27,MAX(H30,$V$13*I30),0)+
    IF(F30=$AE$28,MAX(MAX(,$V$13,$B$22*E30,$D$14)*I30,H30),0)+
    IF(F30="Container",H30*I30,0)+
    IF(F30="flat",H30,0)+
    IF(F30="CBM",MAX(MAX($V$13/E30,$B$22)*I30,H30),0)+
    IF(OR(F30="%",F30="Skid",F30="Metric Ton"),MAX(MAX($V$13,$B$22*E30)*I30,H30,$D$22),0))
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Regular
    Joined
    Feb 2011
    Posts
    20
    Location
    Changed it a bit to match the Metric Ton way to calculate but works great. thanks...

    =IF(F30="","",IF(F30=$AE$27,MAX(H30,$V$13*I30),0)+
    IF(F30=$AE$28,MAX(MAX(,$V$13,$B$22*E30,$D$14)*I30,H30),0)+
    IF(F30="Container",H30*I30,0)+
    IF(F30="flat",H30,0)+
    IF(F30="CBM",MAX(MAX($V$13/E30,$B$22)*I30,H30),0)+
    IF(OR(F30="METRIC TON"),MAX($V$13/1000*I30,H30),0))

  7. #7
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    I know it's solved but..
    I noticed that the formula hinges on F30, and that F30 had Data Validation based on the range AE24:AE31, so I've used that range in MATCH to return a number and used that in the CHOOSE function which will allow more choices (up to 254) if necessary in future. When you open the CHOOSE Function Arguments dialogue box, it's a lot clearer to see which formulae you're applying than doing the same with an IF function. So far in minor testing it returns the same values as yours.

    [VBA]=IF(F30="","",IF(ISERROR(MATCH(F30,AE24:AE28,0)),MAX(MAX($V$13,$B$22*E30)*I 30,H30,$D$22),CHOOSE(MATCH(F30,AE24:AE28,0),MAX(MAX($V$13/E30,$B$22)*I30,H30),H30*I30,H30,MAX(H30,$V$13*I30),MAX(MAX($V$13,$B$22*E30, $D$14)*I30,H30))))[/VBA]

    I'm using Excel 2003 at the moment and the formula can be shorter with XL2007/2010's IFERROR function, but I daren't post what I think it might be as I can't test.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  8. #8
    VBAX Regular
    Joined
    Feb 2011
    Posts
    20
    Location
    Thanks for the extra feedback P. havent had much time over the last few days to play around with it. I plugged your formula in my original file and it didnt seem to work. I'll test a few things and let you know if it works. I like the fact that I can add more parameters to F30

  9. #9
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Quote Originally Posted by PEV
    Thanks for the extra feedback P. havent had much time over the last few days to play around with it. I plugged your formula in my original file and it didnt seem to work. I'll test a few things and let you know if it works. I like the fact that I can add more parameters to F30
    Well, I just tested it again and it worked on your supplied file. It did it not 'seem to work' isn't very informative - in what way didn't it work?
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •