+ Reply to Thread
Results 1 to 11 of 11

Lookup Function - Gives Wrong Value

  1. #1
    Registered User
    Join Date
    01-01-2011
    Location
    Saudi Arabis
    MS-Off Ver
    Excel 2007
    Posts
    5

    Lookup Function - Gives Wrong Value

    Hello there,

    I am using Microsoft Office 2007 on Windows XP.
    I want to apply formula LOOKUP(C2;G2:G5;H2:H5) on D2

    C2 Enter Value
    D2 RESULT

    G2 HALF HOUR G3 ONE HOUR G4 ONE AND HALF HOUR G5 TWO HOURS
    H2 0 H3 5 H4 10 H5 15

    When i enter Half Hour in C2, it gives me 0 in D2 which is correct.
    For One Hour and Two Hours, i get the correct values.
    But for One And Half Hour i get the value as 5 instead of 10.

    What might be the mistake
    Thanks
    Attached Images Attached Images

  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: Lookup Function - Gives Wrong Value

    Hello,

    Lookup() requires the data in the lookup range to be sorted ascending, and it is not sorted that way in your data. I think you can achieve what you want to do with Vlookup() instead:

    =VLOOKUP(C2,G2:H5,2,FALSE)

    cheers,

  3. #3
    Registered User
    Join Date
    01-01-2011
    Location
    Saudi Arabis
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Lookup Function - Gives Wrong Value

    Hi,

    If you can view the attachment, i have the values in ascending order.
    And
    The formula which you gave, seems to be incorrect.
    Please view the attachment.

    Thanks a lot for reply
    Attached Images Attached Images

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Lookup Function - Gives Wrong Value

    To best describe or illustrate your problem you would be better off attaching a dummy workbook not an image, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

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

    Re: Lookup Function - Gives Wrong Value

    If you can view the attachment, i have the values in ascending order.
    Really? Have a closer look. Your values are in this order:

    half hour
    one hour
    one and half hour
    two hours

    If you select the four cells and sort them via Data - sort, they will be arranged like this:

    half hour
    one and half hour
    one hour
    two hours

    And that is an alphabetical sort. "one and" comes before "one hour". So, no, your data is not sorted ascending, hence the Lookup() fails. The Vlookup() I suggested above does not depend on sort order if the last parameter is FALSE.

    See attached workbook for a working solution of the formula I suggested above. I tend to test solutions before I post them.

    The error you get is based on your system using the ; (semicolon) where my system uses the , (comma). This is a difference between regional settings of our respective computers and has nothing to do with the correctness of the formula. If you open the attached workbook, you will see the formula with your regional syntax.

    Be aware that when you post on an international forum, other people's system settings may vary from yours, so if you copy a formula from the forum, you may need to replace , (commas) with ; (semicolons) before the formulas work on your machine.

    cheers,
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    01-01-2011
    Location
    Saudi Arabis
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Lookup Function - Gives Wrong Value

    Here you are

    Please find the attached Excel File.

    Thanks
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    01-01-2011
    Location
    Saudi Arabis
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Lookup Function - Gives Wrong Value

    Mr. teylyn

    I saw your book7.xlsx.
    Your book works fine.
    I corrected the ascending order in my book. And there was a mistake in the formula, i corrected that but still ONE AND HALF HOUR value is incorrect.

    But still it gives me wrong value.

    Can you see my attached book.

    Thanks
    Attached Files Attached Files

  8. #8
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Lookup Function - Gives Wrong Value

    Hi saleh_binmasood
    you could use
    =VLOOKUP(C2,G2:H5,2,FALSE)
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  9. #9
    Registered User
    Join Date
    01-01-2011
    Location
    Saudi Arabis
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Lookup Function - Gives Wrong Value

    Thanks A Lot. The problem is solved with the use of VLOOKUP Function.
    I will work with the LOOKUP now.

    Thank you once again Mr. TEYLYN

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

    Re: Lookup Function - Gives Wrong Value

    I agree you should really be using a VLOOKUP with FALSE here, the above is in fact a reiteration of post # 2 - the very first response.

    If you want to use lookup (useful in the right context) - the reason yours fails is that your lookup_vector does not have the correct precedent range.

    Please Login or Register  to view this content.
    note also - not everyone who uses Excel is male - you might find MR.Teylyn takes exception to that assumption.

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

    Re: Lookup Function - Gives Wrong Value

    Hi all,

    @saleh_binmasood, the formula I posted in post #2 is exactly what my friend pike pointed out in post #8

    Me in #2
    =VLOOKUP(C2,G2:H5,2,FALSE)

    Pike in #8
    =VLOOKUP(C2,G2:H5,2,FALSE)

    I wish you would take as much care in testing and applying the suggestions provided by the members here, as the members here do in constructing them.

    Initially, while constructing your workbook, please do not pay any attention to fancy formatting and overlaying text boxes. Concentrate on the actual formulas. Once you're sure your calculations are correct, please delve into the fancy fonts and stuff, but make sure that your overlaying rectangles and text boxes still allow you to enter data. In the file you uploaded last, this was not the case.

    And, yes, as DonkeyOte has pointed out, not all members who give advice here are male.

    Have a great year 2011.

    cheers,

+ 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