Excel VLOOKUP Function - The Ultimate Guide
Excel VLOOKUP Function - The Ultimate Guide
TO EXCEL VLOOKUP
FUNCTION
2. VLOOKUP Example 1
Finding Brad's Math Score
3. VLOOKUP Example 2
Two-Way Lookup
4. VLOOKUP Example 3
Using Drop Down Lists as Lookup Values
5. VLOOKUP Example 4
Three-way Lookup
6. VLOOKUP Example 5
Getting the Last Value from a List using the Excel VLOOKUP
Function
7. VLOOKUP Example 6
Partial Lookup using Wildcard Characters and VLOOKUP
function
8. VLOOKUP Example 7
VLOOKUP Returning an Error Despite a Match in Lookup Value
9. VLOOKUP Example 8
Case Sensitive Lookup using the VLOOKUP Function
In this brief guide, I'll cover everything there is to know about the
VLOOKUP function, and then show the power if it by using examples.
Let's take a simple example here to understand when to use the Excel
VLOOKUP function.
Remember when the exam score list was out and pasted on the notice
board and everyone used to go crazy finding their names and their
score (at least that's what used to happen when I was in school).
You go up to the notice board and start looking for your name or
enrolment number (running your finger from top to bottom in the
list).
As soon as you spot your name, you move your eyes to the right of
the name/enrolment number to see your scores.
And that is exactly what VLOOKUP function does for you (feel free to
use this example in your next interview).
VLOOKUP function looks for a specified value in a column (in the above
example, it was your name) and when it finds the specified match, it
returns a value in the same row (the marks you obtained).
Syntax
=VLOOKUP(lookup_value, table_array,
col_index_num,[range_lookup])
Input Arguments
lookup_value this is the look-up value you are trying to find in the
left-most column of a table. It could be a value, a cell reference, or a
text string. In the score sheet example, this would be your name.
table_array this is the table in which you are looking for the value.
This could be a reference to a range of cells or a named range. In the
score sheet example, this would be the entire table that contains
score for everyone for every subject
col_index this is the column number from which you want to
fetch the matching value. In the score sheet example, if you want
the scores for Math (which is the first column in a table that
contains the scores), you'd look in column 1. If you want the scores
for Physics, you'd look in column 2.
[range_lookup] here you specify whether you want an exact
match or an approximate match. If omitted, it defaults to TRUE
approximate match (see additional notes below).
Now let's get to work and use the VLOOKUP function for what it does
best. From the above data, I need to know how much Brad scored in
Math.
Here is the VLOOKUP formula that will return Brad's Math score:
=VLOOKUP("Brad",$A$3:$E$10,2,0)
First, it looks for the value Brad in the left most column. It goes from
top to bottom and finds the value in cell A6.
As soon as it finds the value, it goes to the right in the second column
and fetches the value in it.
You can use the same formula construct to get anyone's marks in any
of the subjects.
For example, to find Maria's marks in Chemistry, use the following
formula:
=VLOOKUP("Maria",$A$3:$E$10,4,0)
For example, if you have a cell with a student's name, and you are
fetching the score for Math, the result would automatically update
when you change the student's name.
For example, in the example below, if I change the name from Brad to
Jill, the result in G4 would automatically update and return 75 (which is
Jill's score in Math).
Click here to see a live demo of how this works.
If you enter a lookup value that is not found in the left-most column, it
returns a #N/A error.
VLOOKUP Example 2
Two-Way Lookup
But what if you want to make both the VLOOKUP value and the
column number dynamic.
For example, in the example below, a two-way lookup means that you
can change the name of the student as well as the name of the subject
and it will fetch the correct score from the table
=VLOOKUP(G4,$A$3:$E$10,MATCH(H3,$A$2:$E$2,0),0)
MATCH function takes the subject name as the lookup value (in H3)
and returns its position in A2:E2. Hence, if you use Math, it would
return 2 as Math is found in B2 (which is the second cell in the specified
array range).
Want to learn more about MATCH Function - click here for a tutorial
with examples and video.
VLOOKUP Example 3
Using Drop Down Lists as Lookup Values
A good idea in such cases is to create a drop down list of the lookup
values (in this case, it could be student names and subjects) and then
simply choose from the list. Based on the selection, the formula would
automatically update the result.
This makes a good dashboard component as you can have a huge data
set with hundreds of students at the back end, but the end user (let's
say a teacher) can quickly get the marks of a student in a subject by
simply making the selections from the drop down.
How to make this:
=VLOOKUP(G4,$A$3:$E$10,MATCH(H3,$A$2:$E$2,0),0) T
he lookup values have been converted into drop-down lists.
Select the cell in which you want the drop-down list. In this
example, in G4, we want the student names.
Go to Data --> Data Tools --> Data Validation.
In the Data Validation Dialogue box, within the settings tab, select
List from the Allow drop-down.
In the source, select $A$3:$A$10
Click OK.
Now you'll have the drop-down list in cell G4. Similarly, you can create
one in H3 for the subjects.
VLOOKUP Example 4
Three-way Lookup
=VLOOKUP(G4,CHOOSE(IF(H2="Unit
Test",1,IF(H2="Midterm",2,3)),$A$3:$E$7,$A$11:$E$
15,$A$19:$E$23),MATCH(H3,$A$2:$E$2,0),0)
This formula uses the CHOOSE function to make sure the correct table
is referred to.
CHOOSE(IF(H2="Unit
Test",1,IF(H2="Midterm",2,3)),$A$3:$E$7,$A$11:$E$
15,$A$19:$E$23)
Doing this makes the VLOOKUP table array dynamic and hence makes
Getting the Last Value from a List using the Excel VLOOKUP
it a three-way lookup.
Function
I dont think you would ever need any calculation involving such a
large number. And that is exactly what we can use get the last number
in a list.
Suppose you have a dataset (in A1:A14) as shown below and you want
to get the last number in the list.
Here is the formula you can use:
=VLOOKUP(9.99999999999999E+307,$A$1:$A$14,TRUE)
Also, note that the list doesn't need to be sorted for this formula to
work.
In the same way, you can also use it to return the last text item from
the list. Here is the formula that can do that:
=VLOOKUP("zzz",$A$1:$A$8,1,TRUE)
The same logic follows. Excel looks through all the names, and since
zzz is consider bigger than any name/text starting with alphabets
before zzz, it would return the last item from the list.
VLOOKUP Example 6
Partial Lookup using Wildcard Characters and VLOOKUP
function
Partial look-up is needed when you have to look for a value in a list
and there isnt an exact match.
For example, suppose you have a data set as shown below, and you
want to look for the company ABC in a list, but the list has ABC Ltd
instead of ABC.
You can not use ABC as the lookup value as there is no exact match in
column A. Approximate match also leads to erroneous results and it
requires the list to be sorted in an ascending order.
=VLOOKUP("*"&C2&"*",$A$2:$A$8,1,FALSE)
Using the asterisk on both sides of the lookup value tells Excel that it
needs to look for any text that contains the word in C2. It could have
any number of characters before or after the text in C2.
For example, cell C2 has ABC, so the VLOOKUP function looks through
the names in A2:A8 and searches for ABC. It finds a match in cell A2, as
it contains ABC in ABC Ltd. It doesn't matter if there are any characters
to the left or right of ABC. Until there is ABC in a text string, it will be
considered a match.
Note: VLOOKUP function always returns the first matching value and
stops looking further. So if you have ABC Ltd., and ABC Corporation in a
list, it will return the first one and ignore the rest.
VLOOKUP Example 7
VLOOKUP Returning an Error Despite a Match in Lookup
Value
For example, in the below case, there is a match (Matt), but the
VLOOKUP function still returns an error.
Now while we can see there is a match, what we can not see with a
naked eye is that there could be leading or trailing spaces. If you have
these additional spaces before, after, or in between the lookup values,
it ISN'T an exact match.
This is often the case when you import data from a database or get it
from someone else. These leading/trailing spaces have a tendency to
sneak in.
=VLOOKUP("Matt",TRIM($A$2:$A$9),1,0)
Since this is an array formula, use Control + Shift + Enter instead of just
Enter.
Another way could be to first treat your lookup array with the TRIM
function to make sure all the additional spaces are gone, and then use
the VLOOKUP function as usual.
VLOOKUP Example 8
Case Sensitive Lookup using the VLOOKUP Function
Here is an example:
As you can see, there are three cells with the same name (in A2, A4,
and A5) but with a different alphabet case. On the right, we have the
three names (Matt, MATT, and matt) along with their scores in Math.
To get the values in the helper column, use the =ROW() function. It will
simply get the row number in the cell.
Once you have the helper column, here is the formula that will give
the case-sensitive lookup result.
=VLOOKUP(MAX(EXACT(E2,$A$2:$A$9)*
(ROW($A$2:$A$9))),$B$2:$C$9,2,0)
Note: Since this is an array formula, use Control + Shift + Enter instead
of just enter.
VLOOKUP Example 9
Using VLOOKUP with Multiple Criteria
Suppose you have a data with students name, exam type, and the
Math score (as shown below):
Using the VLOOKUP function to get the Math score for each student
for respective exam levels could be a challenge.
For example, if you try using VLOOKUP with Matt as the lookup value,
it'll always return 91, which is the score for the first occurrence of Matt
in the list. To get the score for Matt for each exam type (Unit Test, Mid
Term and Final), you need to create a unique lookup value.
This can be done using the helper column. The first step is to insert a
helper column to the left of the scores.
Now, to create a unique qualifier for each instance of the name, use
the following formula in C2: =A2&"|"&B2
Copy this formula to all the cells in the helper column. This will create
unique lookup values for each instance of a name (as shown below):
Now, while there were repetitions of the names, there is no repetition
when the name is combined with the level of examination.
This makes it easy as now you can use the helper column values as the
lookup values.
=VLOOKUP($F3&"|"&G$2,$C$2:$D$19,2,0)
Note that while A2 and A3 are different and B2 and B3 are different,
the combinations end up being the same. But if you use a separator,
then even the combination would be different (D2 and D3).
You can easily remove the error values with any meaning full text such
as "Not Available" or "Not Found".
For example, in the example below, when you try to find the score of
Brad in the list, it returns an error as Brad's name is not there in the
list.
=IFERROR(VLOOKUP(D2,$A$2:$B$7,2,0),"Not
Found")
=IF(ISERROR(VLOOKUP(D2,$A$2:$B$7,2,0)),"Not
Found",VLOOKUP(D2,$A$2:$B$7,2,0))
Note: I've tried my best to proof read this guide, but in case you find any errors or spelling
Warning: This is a free guide and you're allowed to share it with anyone who
needs it. You are NOT allowed to sell it or use it for any commercial purposes.
Can't Miss Excel
Resources
Here are some Excel Resources that will skyrocket your Excel learning
and save a lot of time.