+ Reply to Thread
Results 1 to 10 of 10

VLOOKUP fails to find some values

  1. #1
    Registered User
    Join Date
    02-14-2018
    Location
    MD
    MS-Off Ver
    2010
    Posts
    3

    VLOOKUP fails to find some values

    Hi all,

    Started using VLOOKUP today and everything was working beautifully until I used it to match one specific number out of a long list of numbers. All data is formatted as General. There are no spaces in the values. I put together (and attached) a test sheet with a sampling of different numbers to maybe see a pattern in why all my values worked except for one.

    The sheet works like this:
    Initial values are entered in Column A.
    Column B is a formula to subtract Column A from 0.945: =0.945-A2
    Column C is this formula: =VLOOKUP(B2,$E$2:$F$23,2,FALSE)
    Columns E and F are the data. For testing, each value for Column B was added to the data table in each respective row.
    And I added a test in Column G to check whether each value in Column B matches the value in the data table (to rule out spaces, formatting issues, etc.)

    Out of 22 somewhat random numbers, testing for a range of numbers that don't work, 11 gave me #N/A.

    See the attachment, please. Is there something I'm missing? It seems to me that, all else being the same, the specific values shouldn't cause an issue with VLOOKUP.

    Thanks, Shawn
    Attached Files Attached Files

  2. #2
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: VLOOKUP fails to find some values

    I don't claim to fully understand it, but it's related to the Floating Point Precision issue.
    https://support.microsoft.com/en-us/...sults-in-excel


    Try using ROUND on the formula in B
    B2 and filled down
    =ROUND(0.945-A2,5)

    Change the 5 to whatever level of decimal accuracy you want

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,733

    Re: VLOOKUP fails to find some values

    You are suffering from floating point errors in the representation of fractions, where something that looks like 0.853, for example, might actually be stored by Excel as 0.852999999999 or 0.853000000000001 which do not give an exact match. If you change the formula in B2 to this:

    =ROUND(0.945-A2,5)

    and copy this down, then the VLOOKUP formulae all return the expected values.

    Hope this helps.

    Pete

  4. #4
    Registered User
    Join Date
    02-14-2018
    Location
    MD
    MS-Off Ver
    2010
    Posts
    3

    Re: VLOOKUP fails to find some values

    Awesome, that works!

    Thanks to you both!

    So, if they are stored in Excel, as in your example, 0.85299999999, why do they match in the test in column G, but fail to match for VLOOKUP?

  5. #5
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: VLOOKUP fails to find some values

    Like I said I don't 'fully' understand it.

    Long Complicated Story, in a short summary.

    Many decimal values cannot be 'Precisely' represented by a binary system (your PC is a binary system).
    So some rounding happens (this is the part that I can't follow, how/when/why which values get rounded).
    Every system has different methods of dealing with this problem, there are even differences within the same program.
    Different functions within Excel may handle this problem differently than others. So while one function sees them as equal, it's possible other functions won't.

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,058

    Re: VLOOKUP fails to find some values

    Read this and weep. Computers can't count...

    https://support.microsoft.com/en-gb/...sults-in-excel

    It's good to know that even a humble plant can count to 5....

    https://www.sciencenews.org/blog/wil...ap-counts-five
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,733

    Re: VLOOKUP fails to find some values

    It is also to do with the different number of bits (binary digits) used in logical comparisons and in arithmetic. If you put this formula in H2:

    =B2-E2=0

    and copy down, you would expect them all to produce TRUE results, but you will see FALSE values against some of the numbers (i.e. against every value which produces #N/A in your VLOOKUP formula). Arithmetic operations use a greater number of bits to do their calculations compared with logical operations (known as Double Precision, the results of which are converted back to Single Precision), so if the errors are very small then logical operations (like =B2=E2), which use Single Precision may not detect them, but arithmetic operations (and this is what the VLOOKUP function uses) will do. Excel also has its own rules (heuristics) to deal with very small values, especially to determine values that are very close to zero, but they are known only to the Microsoft programmers that wrote them.

    You just have to be wary of these errors, and take steps to avoid them when dealing with fractions.

    Hope this helps.

    Pete.

  8. #8
    Registered User
    Join Date
    02-14-2018
    Location
    MD
    MS-Off Ver
    2010
    Posts
    3

    Re: VLOOKUP fails to find some values

    Ok, very informative, thanks again!

    Well, on the bright side, as an engineer, I'm not at all concerned with precision in arithmetic calculations... oh, wait...

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,058

    Re: VLOOKUP fails to find some values

    You sound just like a mate of mine.... another engineer.!!��

    Me: an analytical chemist...

  10. #10
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: VLOOKUP fails to find some values

    Quote Originally Posted by serrels View Post
    So, if they are stored in Excel, as in your example, 0.85299999999, why do they match in the test in column G, but fail to match for VLOOKUP?
    The inconsistency is not because 0.937 (B7) is actually 0.936999999999999 or 0.937000000000001.

    In fact, the inconsistency arises because that is not the problem(!).

    [EDIT] I was referring to the visible difference. But Pete is correct that there is a difference between the binary representations of the calculated 0.937 and the constant 0.937 that we enter. That difference is indeed due to invisible digits beyond the first 15 significant digits, which is all that Excel displays (formats), an arbitrary limitation.

    Quote Originally Posted by Pete_UK View Post
    Arithmetic operations use a greater number of bits to do their calculations compared with logical operations (known as Double Precision, the results of which are converted back to Single Precision), so if the errors are very small then logical operations (like =B2=E2), which use Single Precision may not detect them, but arithmetic operations (and this is what the VLOOKUP function uses) will do.
    The inconsistency is not due to Double v. Single precision. Comparison operations do not compare values converted to Single precision.

    We can confirm that by comparing 0.937 in K7 and 0.937000000000001 in L7. =K7=L7 returns FALSE, as expected. =vbsingle(K7)=vbsingle(L7) returns TRUE, where vbsingle is the following VBA function.
    Please Login or Register  to view this content.
    Excel always uses Double precision (64-bit floating-point) to store, calculate and compare numeric values.

    But you are correct: Excel is inconsistent in the way that it performs calculations and comparisons.

    In particular, VLOOKUP compares the exact binary representation of values, whereas the equal operator compares the values rounded to 15 significant digits.

    And you demonstrate another example of the inconsistent Excel behavior.

    =B7-E7 returns exactly zero (0.00E+00 when formatted as Scientific) because Excel sometimes arbitrarily replaces the actual arithmetic result with zero.

    But =B7-E7=0 returns FALSE because in that context, Excel does not substitute the actual arithmetic result with zero.

    In fact, even =B7-E7-0 returns non-zero (about 1.11E-16) because the redundant -0 creates a different context in which Excel does not make the substitution.

    The SUM function is also inconsistent. If S7 is =-E7, =SUM(B7,S7) returns 0.00E+00, but =SUM(B7,-E7) returns about 1.11E-16.

    These are simply examples of Excel's inconsistent and, IMHO, defective implementation, not the 64-bit floating-point standard.
    Last edited by joeu2004; 02-14-2018 at 05:06 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Vlookup fails
    By Visvang in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-07-2017, 07:22 AM
  2. Replies: 1
    Last Post: 04-30-2014, 05:49 PM
  3. Range.Find function fails to find a match but For loop confirms that match exists
    By 6StringJazzer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-08-2013, 03:35 PM
  4. find method fails to find custom format date
    By yot68 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-03-2012, 06:28 PM
  5. message in case FIND fails
    By yot68 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-01-2011, 09:36 AM
  6. FileSearch fails to find shortcuts!
    By bagullo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-07-2011, 09:39 AM
  7. CommandButton and FIND fails
    By JBeaucaire in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-16-2009, 05:18 PM

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