Vlookup returns data that partially matches cell

M

MikkiFes

I am using VLOOKUP to search by Employee number and match data.

However, I was informed today that a letter I recently sent went to an
incorrect address. I traced the problem back to the following scenario:

Employee 1 : 1234 (Employee whose data I needed)
Employee 2: 111234 (Employee whose data was returned.)

Generally speaking I prefer to use SSN's where possible as I am accounting
for Benefits that affect W-2 taxable wages. The base file I got from the
Third-party vendor displayed SSN ###-##-NNNN so I had to use the EE# in this
case as it was the only other "unique" identifier.

I always use the Function Arguements box and enter FALSE in the range_lookup
logical field, so that is not the issue. I'm not using any wildcards either.
My dataset can be in the tens of thousands, depending on which files I'm
using at any given time.

Thanks!
 
J

Joel

Read the Vlook help menu I added below. VLOOKUP requires the items to be in
ascending order. Doing a sort as stated below will fix the problem. What is
happening is if you have the numbers 1 2 5 7 6 8 and you want 8 VLOOKUP will
pick 7 which is the largest number. VLOOKUP stops because it see 6.


VLOOKUP

See Also

Searches for a value in the leftmost column of a table, and then returns a
value in the same row from a column you specify in the table. Use VLOOKUP
instead of HLOOKUP when your comparison values are located in a column to the
left of the data you want to find.

The V in VLOOKUP stands for "Vertical."

Syntax

VLOOKUP(lookup_value,table_array,col_index_num,range_lookup)

Lookup_value is the value to be found in the first column of the array.
Lookup_value can be a value, a reference, or a text string.

Table_array is the table of information in which data is looked up. Use a
reference to a range or a range name, such as Database or List.

If range_lookup is TRUE, the values in the first column of table_array must
be placed in ascending order: ..., -2, -1, 0, 1, 2, ..., A-Z, FALSE, TRUE;
otherwise VLOOKUP may not give the correct value. If range_lookup is FALSE,
table_array does not need to be sorted.

You can put the values in ascending order by choosing the Sort command from
the Data menu and selecting Ascending.

The values in the first column of table_array can be text, numbers, or
logical values.

Uppercase and lowercase text are equivalent.

Col_index_num is the column number in table_array from which the matching
value must be returned. A col_index_num of 1 returns the value in the first
column in table_array; a col_index_num of 2 returns the value in the second
column in table_array, and so on. If col_index_num is less than 1, VLOOKUP
returns the #VALUE! error value; if col_index_num is greater than the number
of columns in table_array, VLOOKUP returns the #REF! error value.

Range_lookup is a logical value that specifies whether you want VLOOKUP
to find an exact match or an approximate match. If TRUE or omitted, an
approximate match is returned. In other words, if an exact match is not
found, the next largest value that is less than lookup_value is returned. If
FALSE, VLOOKUP will find an exact match. If one is not found, the error value
#N/A is returned.

Remarks

If VLOOKUP can't find lookup_value, and range_lookup is TRUE, it uses the
largest value that is less than or equal to lookup_value.
If lookup_value is smaller than the smallest value in the first column of
table_array, VLOOKUP returns the #N/A error value.
If VLOOKUP can't find lookup_value, and range_lookup is FALSE, VLOOKUP
returns the #N/A value.
Example

The example may be easier to understand if you copy it to a blank worksheet.

How?

Create a blank workbook or worksheet.
Select the example in the Help topic. Do not select the row or column
headers.


Selecting an example from Help

Press CTRL+C.
In the worksheet, select cell A1, and press CTRL+V.
To switch between viewing the results and viewing the formulas that return
the results, press CTRL+` (grave accent), or on the Tools menu, point to
Formula Auditing, and then click Formula Auditing Mode.
The example uses values for air at 1 atm pressure.
 
M

MikkiFes

According to the Help file, I actually though I didn't need to sort the data
because I always use "FALSE" to force it to locate the exact number.

'If range_lookup is TRUE, the values in the first column of table_array must
be placed in ascending order: ..., -2, -1, 0, 1, 2, ..., A-Z, FALSE, TRUE;
otherwise VLOOKUP may not give the correct value. If range_lookup is FALSE,
table_array does not need to be sorted.'

I have a feeling it has to do with the fact that the "exact" number I'm
looking for is indeed included in the larger number, so I will see if sorting
does in fact clear up the issue. Thanks!
 
J

JMB

With False, it should not have mattered if the table was sorted. Even if you
used an approximate match, vlookup should not return 111234 as this value is
*larger* than what you are trying to look up, not the largest value that is
*smaller* than your lookup value.

Check the cell with 111234 in it (let's say this is cell A1). What appears
in the formula bar? Note that what is displayed on the screen is not
necessarily the cells contents - differences possibly due to some sort of
formatting, but check the formula bar to get a better idea of what the cell
contents actually are.

In an adjacent empty cell enter
=A1=1234 (change cell reference to whatever it actually is)
what is returned?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top