+ Reply to Thread
Results 1 to 6 of 6

Trying to avoid long IF statement.

  1. #1
    Registered User
    Join Date
    12-21-2009
    Location
    Ottawa, Canada
    MS-Off Ver
    Excel 2003
    Posts
    3

    Trying to avoid long IF statement.

    I've attached an example of what I am trying to achieve and an explanation as well. I'm trying to avoid the use of a macro as I don't understand them and I will need to modify the sheet later on which could cause problems. However, if a macro is the only solution, then I will have to make due with one.
    Attached Files Attached Files
    Last edited by teylyn; 01-06-2010 at 03:44 PM.

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Trying to avoid long IF statement.

    Hi Lukus

    see the attached.

    I created five columns where all rating results are calculated for each row, and then an INDEX/MATCH function in column F to lookup the one that should be applied to the row. You can hide the columns I to M if they mess up your spreadsheet design.

    hth
    Attached Files Attached Files

  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,719

    Re: Trying to avoid long IF statement.

    There are ways to use that approach but I wouldn't advise it. My preference would be for a formula like this in F6 copied down

    =CHOOSE(MATCH(A6,A$23:A$27,0),1,2,3,4,5)

    [Note: I had to remove the colons from the end of the ratings in A23:A27]

    In that formula you need to replace each digit in 1,2,3,4,5 with the relevant formula, so 1 get's replaced with the formula for "Grease 2-hr" 2 gets replaced with the formula for "Vent 1-hr" etc.

    I'm not sure I could decipher all the formulas but doing it that way you don't need ROW and INDIRECT and you can avoid some of the parentheses, e.g. in the following I added the 2 formula and the 4 formula ["Vent 1-hr" and "Round 1-hr"]

    =CHOOSE(MATCH(A6,A$23:A$27,0),1,(B6*2+C6*2+2)*D6*14/144,3,(B6*3.1416+6)*D6*14/144,5)

    you just need to add the versions for 1, 3 and 5.....

    Edit: this is similar to Teylyn's suggested approach above - this method avoids the helper columns.......but you get quite a long, complex formula in return.....
    Last edited by daddylonglegs; 01-05-2010 at 05:33 PM.

  4. #4
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Trying to avoid long IF statement.

    Daddylongleg's suggestion is putting it all in one formula, but the principle is basically the same. Each version has its benefits, i.e.

    - DLL's solution is more elegant and does not require helper columns,
    - my solution shows you the results of the individual calculations and it may be easier to maintain the formulae.

    you can use the formulae in my spreadsheet to copy and paste into DLL's formula....

    hth

  5. #5
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Trying to avoid long IF statement.

    There are two options in workbook

    EDIT:

    Oops
    seems I late
    Attached Files Attached Files
    Last edited by contaminated; 01-05-2010 at 05:43 PM.
    Люди, питающие благие намерения, как раз и становятся чудовищами.

    Regards, ?Born in USSR?
    Vusal M Dadashev

    Baku, Azerbaijan

  6. #6
    Registered User
    Join Date
    12-21-2009
    Location
    Ottawa, Canada
    MS-Off Ver
    Excel 2003
    Posts
    3

    [Solved] Re: Trying to avoid long IF statement.

    Thank you guys... both solutions achieve what I wanted.

    I think I prefer Teylyn's approach as it keeps all formulas to a minimal size and therefore, easier to maintain as he mentioned.

+ 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