+ Reply to Thread
Results 1 to 18 of 18

Excel - problem with IF

  1. #1
    Registered User
    Join Date
    10-25-2006
    MS-Off Ver
    Office 365
    Posts
    51

    Excel - problem with IF

    Hello can someone help me with the following problem :

    I need to classify if the values below :

    less than 1 receives value low
    between than 1 and 2 receives value mid
    more than 2 receives value hig


    0,1 low
    1,3 mid
    0,2 mid
    5,1 hig


    any help is appreciated - thanks !

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

    Re: Excel - problem with IF

    You'll have to edit this for your country layout, but a LOOKUP() seems to be the ticket here:


    =LOOKUP(A1, {0,1,2}, {"low", "mid", "high"})
    ...or
    =LOOKUP(A1; {0;1;2}, {"low"; "mid"; "high"})
    _________________
    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!)

  3. #3
    Registered User
    Join Date
    10-25-2006
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Excel - problem with IF

    i think i have expressed myself not clear....


    0.001 LOW
    1.051 MID
    5.001 HIG


    any chance to do it with IF or any other function ?

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

    Re: Excel - problem with IF

    What's wrong with upper solution?
    Never use Merged Cells in Excel

  5. #5
    Registered User
    Join Date
    10-25-2006
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Excel - problem with IF

    I used on cell N3 :

    =LOOKUP(L3, {0,1,2}, {"low", "mid", "high"})


    for a L3 cell with value : 1,1813


    and got: "The formula you typed contains an error"

  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,059

    Re: Excel - problem with IF

    Did you try second one?

    =LOOKUP(L3; {0;1;2}, {"low"; "mid"; "high"})

  7. #7
    Registered User
    Join Date
    10-25-2006
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Excel - problem with IF

    yep... same error.....

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Excel - problem with IF

    There should be another semi-colon in there:


    =LOOKUP(L3; {0;1;2}; {"low"; "mid"; "high"})
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  9. #9
    Forum Contributor bentleybob's Avatar
    Join Date
    02-27-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    644

    Re: Excel - problem with IF

    What''s wrong with

    =IF(B6<1,"low",IF(B6<=2,"mid","high"))

    ?

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

    Re: Excel - problem with IF

    Bentley, the "what's wrong" question misses the main point, efficiency. IF/THEN is fine for a couple of tests, but starting with 3 and up I always switch to one of the many lookup functions available. Once you start using them for longer IF/THEN scenarios, you'll find they're easier to read and edit.

    LOOKUP() functions with inline arrays like we've shown in this thread is good for smaller sets of ranged options, 3-6. But around 6 I always put the actual ranges into a table on the workbook which makes updating the table a breeze.

    =LOOKUP(A1; $P$1:$P$6; $Q$1:$Q$6)
    Last edited by JBeaucaire; 12-20-2010 at 07:49 PM.

  11. #11
    Forum Contributor bentleybob's Avatar
    Join Date
    02-27-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    644

    Re: Excel - problem with IF

    Not wanting to get into a p***g match with you Jerry, but:

    (a) The OP only specified low, medium, and high, so it hardly qualifies as something in need of "efficiency", as you put it;
    (b) My formula can hardly be considered hard to read or edit; and
    (c) The use of arrays is rather complex for some users.

    That all being said, I do agree that your solution is more efficient and certainly more elegant.

    Cheers.

  12. #12
    Registered User
    Join Date
    10-25-2006
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Excel - problem with IF

    ok... the formula =LOOKUP(L3; {0;1;2}; {"low";"mid";"high"}) worked now...

    noted that it used ; for the entire formula.....

    the another example with IF, didn't worked yet... not sure why

    anyway i appreciated your attention !

  13. #13
    Registered User
    Join Date
    10-25-2006
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Excel - problem with IF

    where do i mark this thread as solved ???

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

    Re: Excel - problem with IF

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  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

    Re: Excel - problem with IF

    Quote Originally Posted by bentleybob View Post
    Not wanting to get into a p***g match with you Jerry...
    No p***g match going on that I can see. Everyone should feel free to posit solutions and opinions and support them. We all learn, and we all then choose what works best for us. Everybody wins.


  16. #16
    Registered User
    Join Date
    10-25-2006
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Excel - problem with IF

    sorry guys ... i'm trapped again... with my own formula tuning now....

    using : =LOOKUP(L4; {0,4999;1,2999;2,4999;2,5}; {"A";"B";"C";"D"})

    i'm getting a 1,5931 value classified as B ...

    if value is from 0 - 0,4999 should be A
    if value is from 0,5 - 1,2999 should be B
    if value is from 1,3 - 2,4999 should be C
    if value is from 2,5 - all higher should be D

    any hint ?

  17. #17
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Excel - problem with IF

    =lookup(l4; {0;0,5;1,3;2,5}; {"a";"b";"c";"d"})
    Entia non sunt multiplicanda sine necessitate

  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

    Re: Excel - problem with IF

    If it's not obvious yet, the LOOKUP() formula lists only the start of each range. Compare SHG's formula to your own and you'll see what I mean.

+ 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