Professional Documents
Culture Documents
? Excel VLOOKUP - Massive Guide With 8 Examples
? Excel VLOOKUP - Massive Guide With 8 Examples
? Excel VLOOKUP - Massive Guide With 8 Examples
com/formulas_macros/
vlookup-in-excel/?
Excel VLOOKUP – Massive Guide with 8
Examples
VLOOKUP is one of the most useful and important functions in Microsoft Excel. It is
generally used to look up a particular value in huge data sheets where manual intervention
can be cumbersome. The alphabet ‘V’ in VLOOKUP stands for “Vertical” so this function is
sometimes also called vertical lookup.
The term “Vertical” signifies that it can be used to look up values vertically i.e. it can be used
to look up values inside a column.
You can also read my previous post: “How to alphabetize in Excel”, there I had used Excel
VLOOKUP to sort a list.
Note: This is a long post of over 2700+ words. If you don’t want to read the whole post, you
can use the below jump links to navigate to the desired section.
According to Microsoft Excel VLOOKUP can be defined as a function, “that looks for a
value in the leftmost column of a table, and then returns a value in the same row from a
column you specify. By default the table must be sorted in an ascending order.”
Here, ‘lookup_value’ specifies the value to be searched inside the ‘table_array’. It can
either be a value or a reference.
‘table_array’ is the range with two or more columns. ‘table_array’ argument can receive
a range reference or a named range. The leftmost column of this range must contain the
‘lookup_value’.
‘column_index’ is the relative index of the column whose value needs to be returned by the
VLOOKUP function. A ‘column_index’ 1 would return values from the first column in the
‘table_array’. Similarly ‘column_index’ 2 would return values from the second column in
the ‘table_array’.
‘range_lookup’ is a Boolean value that specifies whether you want VLOOKUP to find an
exact match or an approximate match. If its value is ‘True’ then either an approximate or an
exact match will be returned. Here, if an exact match is not found, the next value that is less
than ‘lookup_value’ is returned. If its value is ‘False’ then only exact match will be
returned.
lookup_value: This is the value based on which the lookup is to be performed. In our case
lookup_value is in the cell B4 i.e. “Benjamin Mutricy”.
table_array: This is the range of the table from which the values are to be fetched. Note that
this ‘table_array’ should always contain ‘lookup_value’ in its leftmost column.
col_index_num: This specifies the positional reference of the column that you want the
VLOOKUP to return.
range_lookup: This specifies that whether the match should be exact or approximate. FALSE
specifies exact match.
Example 1: In this example we have a list of students with their scores. Now, here we need
to find the score of a student with the First Name ‘Vincent’.
To find the solution to our problem, we have used the vertical lookup as:
Explanation:
So, we will use the VLOOKUP as: =VLOOKUP(E4,A3:C16,2,FALSE) and it results into
“Schauly”.
Explanation:
Here we have to find the Density of an Element whose atomic mass is 15 or slightly less.
Now, here we can use the vertical lookup formula as: =VLOOKUP(15,A3:B14,2) which
results into 1.25.
Explanation:
Example 4: In this example we have 2 tables as shown below. Our task is to apply a Vertical
Lookup based on ‘Element Names’ and fetch the melting points of the elements from the
second table.
This can be done by using the formula: =VLOOKUP(C3,$F$3:$G$14,2,FALSE)
After applying this formula for the first element we have to drag the formula below (using the
fill handle) for other elements.
Explanation:
The first argument to the function i.e. ‘lookup_value’ = C3 (Reference for first
element).
Second argument i.e. ‘table_array’ = $F$3:$G$14 (Range of Element Table 2) – If
you are wondering what are these ‘$’ signs along with the table reference, then you
should read this post.
Third argument i.e. ‘column_index’ = 2 (the column number whose value the vertical
lookup function should return).
Fourth argument i.e. ‘range_lookup’ = FALSE (Signifies that we only want the exact
match).
Note that the values that I have explained above are only for the first element. Dragging this
formula itself makes the necessary changes in the formula to make it correct for the below
elements as well.
Example 5: In this example we will use wildcard operators along with Vertical Lookup. Here
we have to find the score of the student whose first name starts with ‘A’.
For this we can use the formula: =VLOOKUP("A*",A3:C16,3,FALSE) which gives a result 66.
Explanation:
Generally, we can use following two wildcard operators with Excel VLOOKUP function.
Wildcard Description
‘?’ Denotes any single character.
‘*’ Denotes any number of characters
Note: Simply placing the tilde sign (~) before any wildcard character tells Excel that the
wildcard character (‘*’ or ‘?’) should be treated as a string and not as wildcard operator.
The first argument to the function i.e. ‘lookup_value’ = “A*” (Any word starting
with ‘A’ alphabet).
Second argument i.e. ‘table_array’ = A3:C16 (Range of Student Table).
Third argument i.e. ‘column_index’ = 3 (the column number whose value the vertical
lookup function should return).
Fourth argument i.e. ‘range_lookup’ = FALSE (Signifies that we only want the exact
match).
Explanation:
Here, IF statement checks whether the output of VLOOKUP function is #NA Error or not. IF
the output is #NA error, then it means that current child list item is not present in the master
list. And hence the IF statement writes “Not Exists” in front of it. However if the item is
present in the master list then it writes “Exists”.
Example 7: Translating scores to grades using vertical lookup. Let’s say we have a table with
student scores and now we have to assign them a grade based on their scores.
For this we can use a VLOOKUP as: =VLOOKUP(C3,$F$4:$G$9,2,TRUE) and then drag this
formula to below cells.
Explanation:
The first argument to the function i.e. ‘lookup_value’ = C3 (Reference for first
element).
Second argument i.e. ‘table_array’ = $F$4:$G$9 (Range of scores and grades
table).
Third argument i.e. ‘column_index’ = 2 (the column number whose value the
VLOOKUP function should return).
Fourth argument i.e. ‘range_lookup’ = True (It matches both the exact values and
values slightly lesser).
Example 8: Applying Vertical lookup using a table on another sheet or another workbook. In
all the examples that we have discussed till now, we have applied VLOOKUP on tables that
are on same worksheet. Now let’s redo the task in previous example but this time with the
scores and grade table present on another worksheet sheet.
In this example the “Student Table” is on ‘Sheet1’ while the “Grade and Score table” is on
the ‘Sheet2’. So you can use a VLOOKUP as: =VLOOKUP(C3,Sheet2!$B$3:$C$8,2,TRUE)
Explanation:
The first argument to the function i.e. ‘lookup_value’ = C3 (Reference for first
element).
Second argument i.e. ‘table_array’ = Sheet2!$B$3:$C$8 (Range of scores and
grades table which is present on Sheet2).
Third argument i.e. ‘column_index’ = 2 (the column number whose value the vertical
lookup function should return).
Fourth argument i.e. ‘range_lookup’ = True (It matches both exact and values
slightly lesser).
Tip: While writing such VLOOKUP formulas you can simply navigate to the Sheet where
the table is present and then select the required table. This will automatically insert the
reference of that particular table in the formula.
1. Sub Vertical_lookup_test()
2. Dim Result As Variant
3. Dim myVal As String ' Can be Integer, long, double etc.
4. Dim Rng As Range
5. Dim Clm As Integer
6. Set Rng = ActiveSheet.Range("A:E") ' Set Range
7. myVal = "Florian" ' Value to be searched
8. Clm = 3 ' Column to be fetched
9. Result = Application.VLookup(myVal, Rng, Clm, False)
10. If IsError(Result) Then
11. Result = "Not found!"
12. End If
13. MsgBox Result
14. End Sub
Before using the above code make sure you change the following values:
1. Change Set Rng = ActiveSheet.Range("A:E") to the range that you wish to use.
2. Change myVal = "Florian" to the value that you want the vertical lookup to search. You
can also use the InputBox function to get this value from user during the runtime.
Till now we have seen VLOOKUP functions that only returns a single column. But there are
times when you need a VLOOKUP function to return multiple columns from the specified
row.
So, you have to make a VLOOKUP formula that can fetch multiple columns. The basic idea
behind this is, we will use VLOOKUP as an array function.
Suppose we need to fetch all the details of “Florian”. So we will proceed as:
1. Select the cells (cells equal to the number of columns that you wish to fetch) where you
wish to populate the VLOOKUP results.
3. After this simply hit the Ctrl + Shift + Enter keys. This will enclose the above formula in
curly brackets and the cells that you had selected will show the fetched columns.
Negative VLOOKUP:
In all the previous examples you must have seen that we have always used a ‘lookup_value’
that is present in the leftmost column of the range. So, the question arises, can we use a
‘lookup_value’ which is not in the leftmost column?
See what happens when your ‘lookup_value’ is not on the leftmost side, and you enter a
negative ‘column_index’ hoping to fetch the value to the left of ‘lookup_value’.
A simple way to do this is by building a user defined function (UDF). This function internally
doesn’t use VLOOKUP but it can give you desired results. Below is the UDF:
This UDF uses Match and Offset functions to accomplish the task.
Let’s understand how to use this function. In our example we have a Student Table and we
have to find the first name of “Petit”.
So, we will use this formula as: =NEGATIVE_VLOOKUP("Petit",B:B,-1,FALSE)
Explanation:
Similarly, in the same table if we have to find the first name of the student with 98 Marks in
Science, then the formula would be:
=NEGATIVE_VLOOKUP(98,D:D,-3,FALSE)
While doing data analysis in excel sometimes you may run into situations where you need to
apply a VLOOKUP based on two keys (i.e. based on two ‘lookup_values’).
For example: We have a Student table as shown in the below image. Now, as you can see
that there are two students with First Name “Christophe” (at A4 and A6). So, applying a
VLOOKUP on first name can cause inconsistency. Hence we will apply a VLOOKUP based
on both First name as well as the Last name.
But as we know that Excel VLOOKUP can only have a single ‘lookup_value’. So we need
to create a helper column by appending first name and last name. We can do this by
writing. =A3&" "&B3
Now, we have combined two keys together and hence this new key column would contain
unique values.