+ Reply to Thread
Results 1 to 6 of 6

Using first correct argument in if statement

Hybrid View

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

    Using first correct argument in if statement

    I have a fairly long if statement, goes something like (example)....

    =if(D4<Ht,5,0) + if(D4<Gt,4,0) + if(D4<It,3,0)

    Ht=5
    Gt=4
    It=10

    If I input a value of '4' in D4, it'll output a value of 8. Is there any way that I can have excel output only the value of the first correct argument, so that the value that would be output in this case would be 5?

    Thanks.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Using first correct argument in if statement

    You would need to embed the IFs

    =IF(D4<Gt,4,IF(D4<Ht,5,IF(D4<lt,3,0)))

    alternatively

    =LOOKUP(D4,{0,4,5},{4,5,3})
    Last edited by DonkeyOte; 06-03-2009 at 02:44 AM.

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

    Re: Using first correct argument in if statement

    If I embed the IF statements, I get an error saying I have too many nested if statements. So as far as I know, I have to do it this way.

    As well, the lookup function won't work. It's too complicated for that.

  4. #4
    Registered User
    Join Date
    06-03-2009
    Location
    Saskatoon, Canada
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Using first correct argument in if statement

    Try this:

    =IF(D4<Ht,5,IF(D4<Gt,4,IF(D4<It,3,0)))

    Each IF statement requires a parameter, correct result, wrong result

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Using first correct argument in if statement

    Quote Originally Posted by bruce2444 View Post
    Try this:

    =IF(D4<Ht,5,IF(D4<Gt,4,IF(D4<It,3,0)))

    Each IF statement requires a parameter, correct result, wrong result
    Based on the example parameters I'm not sure that would work given you will never return 4 - ie if Gt < Ht then it follows that if D4 < Ht the Gt will never execute - you will always get the Ht result.

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Using first correct argument in if statement

    perhaps showing us your long if statement would help
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

+ 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