Wednesday, February 10, 2010

Excel VLOOKUP() returns wrong results

I was trying VLOOKUP with a huge array of numerical data and it was returning the wrong results. I did some search on the internet but the results were not really helpful.
I turned to the Excel 2007 help and I found the solution as the following:

range_lookup Optional. A logical value that specifies whether you want VLOOKUP to find an exact match or an approximate match:
  • If range_lookup is either TRUE or is omitted, an exact or approximate match is returned. If an exact match is not found, the next largest value that is less than lookup_value is returned. Important If range_lookup is either TRUE or is omitted, the values in the first column of table_array must be placed in ascending sort order; otherwise, VLOOKUP might not return the correct value.
    For more information, see Sort data.
    If range_lookup is FALSE, the values in the first column of table_array do not need to be sorted.
  • If the range_lookup argument is FALSE, VLOOKUP will find only an exact match. If there are two or more values in the first column of table_array that match the lookup_value, the first value found is used. If an exact match is not found, the error value #N/A is returned.

So omitting the range_lookup value would be interpreted as true which leads approximate matching. It seems excel prefers to use approximate matching instead of exact matching when the range_lookup is not specified. This is werid and against the common sense :)

No comments: