+ Reply to Thread
Results 1 to 5 of 5

selecting first correct argument in if statement

  1. #1
    Registered User
    Join Date
    01-02-2009
    Location
    pittsburgh, pa
    MS-Off Ver
    Excel 2007
    Posts
    52

    selecting first correct argument in if statement

    I have if statements each separated with a '+'. When any are false, they equal zero. If any are true, they output the number calculated in the argument.

    The problem I'm having is in some cases, more than 1 if statement is true, so it adds them together. However, I only want it to spit out the value for the first true if statement.

    Is there any function I can use to accomplish this?

    I've attempted the CHOOSE function but that won't work. This if statement is contained in around 50 rows (it uses vba so even though the arguments are the same, the numbers are always different)...

    i.e.

    row 4: if(d4=....
    row 5: if(d5=....

    etc...

    Thanks.

  2. #2
    Registered User
    Join Date
    04-16-2009
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: selecting first correct argument in if statement

    could you post one complete formula?

  3. #3
    Registered User
    Join Date
    01-02-2009
    Location
    pittsburgh, pa
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: selecting first correct argument in if statement

    =IF(D5="","",IF(D5>=ROUNDDOWN(Ht-Sh_1,0.0001),Td_1+(taper_1*(Ht-D5)*12), 0)+IF(AND(D5<Ht-Sh_1,D5>=ROUNDDOWN(Ht-Sh_1-Sh_2+(O_1/12),0.0001),D5<>Cp_1-E5,D5<>Cp_1-E5-E4),Td_2+(taper_2*(Cp_1-D5)*12),0)+IF(AND(D5<Ht-Sh_1-Sh_2+((O_1+O_2)/12),D5>=ROUNDDOWN(Ht-Sh_1-Sh_2-Sh_3+((O_1+O_2)/12),0.0001),D5<>Cp_2- E5,D5<>Cp_2-E5-E4),Td_3+(taper_3*(Cp_2-D5)*12),0)+IF(AND(D5<Ht-Sh_1-Sh_2-Sh_3+((O_1+O_2+O_3)/12),D5>=ROUNDDOWN(Ht-Sh_1-Sh_2-Sh_3-Sh_4+((O_1+O_2+O_3)/12),0.0001),D5<>Cp_3-E5,D5<>Cp_3-E5-E4),Td_4+(taper_4*(Cp_3-D5)*12),0)+IF(AND(D5<Ht-Sh_1-Sh_2-Sh_3-Sh_4+((O_1+O_2+O_3+O_4)/12),D5>=ROUNDDOWN(Ht-Sh_1-Sh_2-Sh_3-Sh_4-Sh_5+((O_1+O_2+O_3+O_4)/12),0.0001),D5<>Cp_4-E5,D5<>Cp_4-E5-E4),Td_5+(taper_5*(Cp_4-D5)*12),0)+IF(AND(D5<Ht-Sh_1-Sh_2-Sh_3-Sh_4-Sh_5+((O_1+O_2+O_3+O_4+O_5)/12),D5>=ROUNDDOWN(Ht-Sh_1-Sh_2-Sh_3-Sh_4-Sh_5-Sh_6+((O_1+O_2+O_3+O_4+O_5)/12),0.0001),D5<>Cp_5-E5,D5<>Cp_5-E5-E4),Td_6+(taper_6*(Cp_5-D5)*12),0))

  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: selecting first correct argument in if statement

    Rather post an example with explanation in it

  5. #5
    Registered User
    Join Date
    01-02-2009
    Location
    pittsburgh, pa
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: selecting first correct argument in if statement

    Somebody else wrote the program last year, I've just been left in charge of modifying it and fixing it up. While I understand (for the most part) what the formula is doing, it'll be almost nearly impossible to explain.

    Moreover, I've been able to make temporary fixes to the code to get it to only call out 1 if statement as being correct when it spits out more than 1, but there are so many scenarios that we run that there's almost always an exception to the code somewhere along the lines whether it be at E4, E10, E20, etc.... And instead of modifying the code to fix the errors every single time, I decided the best way to go was to try to figure out a function or something that will allow it to call out the first true if statement.

+ 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