13 Vlookup

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

http://www.excelfunctions.net/Excel-Vlookup-Tutorial.

html

What is Vlookup?
 Vlookup (short for 'vertical' lookup) is a built-in Excel function that is designed to work with data
that is organised into columns.
 For a specified value, the function finds (or 'looks up') the value in one column of data, and
returns the corresponding value from another column.

Vlookup Example
Imagine that your company keeps a spreadsheet of employee hourly rates of pay (see 'Hourly
Pay' spreadsheet below). At the end of each week, the sales team manager sends you a list of
hours worked by each of his staff during the week (see 'Sales Team Hours' spreadsheet below).
It is your job to complete the 'Sales Team Hours' spreadsheet, to show the pay owed to each
member of the sales team.

In order to calculate the pay owed to each sales team member, you first need to look up the hourly
rate of pay for each person and insert this into column C of the 'Sales Team Hours' spreadsheet. This
can be done using the Excel Vlookup function.

As illustrated below, if the Vlookup function is entered into cell C2 of the 'Sales Team Hours'
spreadsheet, this can look up the name "Benson, Paul" in column A of the 'Hourly Pay'
spreadsheet and return the corresponding rate of pay from column B. Therefore, in this example,
the Vlookup function returns the value $32.00.
Exact Match vs. Closest Match
n the above example the Vlookup function is used to find an exact match to the lookup value
(which is the text string "Benson, Paul").
The Vlookup function can also be used to return a closest match to the lookup value if an exact
match is not found.
Vlookup Syntax
The syntax of the Excel Vlookup function is:

VLOOKUP (lookup_value, table_array, col_index_num, [range_lookup] )


where the function arguments are:

lookup_value - The value that you want to search for.

table_array - The array of data that is to be searched for the lookup_value.


Note: The Vlookup function searches in the left-most column of
this array.

col_index_num - An integer, specifying the column number of the


supplied table_array, that you want to return a value from.

[range_lookup] - An optional logical argument that describes what the function


should return in the event that it does not find an exact match to
the lookup_value.
The [range_lookup] can be set to TRUE or FALSE, meaning:
TRUE - If an exact match is not found, use the closest
match below the lookup_value.
Note: if this option is used, the left-hand
column of the table_arraymust be in ascending
order.
FALSE - If an exact match to the lookup_value is not
found, return an error.
If the [range_lookup] value is omitted, it uses the default value of
TRUE.

Rules for the Vlookup Using an Exact Match Rules for the Vlookup Using the
Closest Match
If the [range_lookup] argument is set to FALSE,
the Vlookup searches for an exact match to If the [range_lookup] argument is
the lookup_value. If an exact match is not set to TRUE (or omitted),
found, the function returns the #N/A error. the lookup_value is matched to
In this case, the following rules apply: the closest value below or equal
 If the lookup_value is duplicated in the left- to this value.
hand column of the table_array, the function In this case, the following rules
uses the first match that it encounters. apply:
 If the lookup_value is a text string, you can use
wildcard characters, where the character ?  The left hand column of the
matches any single character and the asterix, * supplied table_array must be in
matches any set of characters. ascending order. If it isn't, the
For example, a lookup_value "t*" would match function may return
any text string beginning with the character unpredictable results.
"t".  If the lookup_value is smaller
than all of the values in the left-
hand column of the table_array,
the Vlookup function returns the
#N/A error.

Vlookup Exact Match Example


In this example, the Excel Vlookup function is used to 'look up' the amount of pay owed to each
member of a sales team during the previous week.

As shown below, the employee hourly rates of pay are stored in one spreadsheet, and a list of
hours worked during the previous week, are stored in a second spreadsheet.

Hourly Pay: Sales Team Hours Worked:


In order to complete the "Sales Team Hours" spreadsheet, so that it shows the pay owed to each
sales team member, you first need to 'look up' each persons rate of pay from the "Hourly Pay"
spreadsheet.

In the spreadsheet below, cells C2-C4 of the "Sales Team Hours" spreadsheet have been updated
with the Vlookup function, which looks up the hourly pay rates for each of the sales team
members.

Sales Team Hours Worked with Vlookup Functions:

The results of these Vlookup functions are shown in the spreadsheet below. As expected, each
team member's hourly rate of pay has been inserted into the corresponding cell in column C.

Sales Team Hours Worked with Vlookup Function Results:

Vlookup Example Explained


The first call to the Vlookup function, in C2 is:

=VLOOKUP( A2, 'Hourly Pay'!A:B, 2, FALSE )

The table below explains the arguments that are supplied to this function:
A2 - Cell A2 is the lookup_value (i.e. the value to be searched for).
The lookup_value is therefore the text string "Benson, Paul".

'Hourly Pay'!A:B - The table_array is made up of columns A-B of the "Hourly Pay" spreadsheet.
The Vlookup function will search down the leftmost column (i.e. column A) of this
array, when searching for the text string "Benson, Paul".

2 - The col_index_num argument is set to the value 2, which tells the Vlookup function
that the value to be returned should be taken from column 2 of the
supplied table_array (i.e. from column B of the "Hourly Pay" spreadsheet).

FALSE - The [range_lookup] argument is set to FALSE, which tells the Vlookup function
that we require an exact match to the lookup_value.
If an exact match is not found, then the Vlookup function should return an error.

This page shows how to use the Excel Vlookup Function when the [range_lookup] argument is
set to TRUE (or is omitted).
When the [range_lookup] is set to TRUE, this tells the Vlookup function that, if an exact match to
the lookup_value is not found, then the closest match below the lookup_value should be
returned instead.
It is important to remember that, when using this option, the left-hand column of
the table_array must be in ascending order. If it isn't, the results from the Vlookup function may
be unpredictable.

Vlookup Closest Match Example


Balance Interest Rate

$0 - $999.99 1%

$1,000 - $4,999.99 3%

$5,000 - $19,999.99 4%

Over $20,000 5%

Imagine a bank account has a variable interest rate that depends upon its balance, as shown in
the table on the right. These interest rate categories are stored in the "Interest Rate" spreadsheet
below.
The "Bank Accounts" spreadsheet below shows several bank accounts, along with their current
balances.

Interest Rates: Bank Accounts:

Column C of the "Bank Accounts" spreadsheet is currently blank, but this column needs to be
updated with the interest rate that is to be applied to each bank account, depending on the
account's current balance. This can be done using the Vlookup function, as shown below:

Bank Accounts spreadsheet with Vlookup functions:

For each of the bank accounts in the above spreadsheet, the Vlookup function finds the closest
value below the current balance, in column A of the "Interest Rates" spreadsheet. The function
then returns the corresponding value from column C of this spreadsheet.
The results of the Vlookup functions are shown below:

Bank Accounts spreadsheet with Vlookup results:

Vlookup Example Explained


The first call to the Vlookup function, in cell C2 is:

=VLOOKUP( B2, 'Interest Rates'!A2:C5, 3, TRUE )

The table below explains the arguments that are supplied to this function:
B2 - Cell B2 is the lookup_value (i.e. the value to be searched for).
The lookup_value is therefore the value 5.69.

'Interest Rates'!A2:C5 - The table_array is the range A2-C5 of the "Interest Rates" spreadsheet.
The Vlookup function will search down the left column (i.e. column A) of this array, when
searching for the closest match equal to or below the lookup_value 5.69.

3 - The col_index_num argument is set to the value 3, meaning that the value to be returned
by the Vlookup function should be taken from column 3 of the supplied table_array (i.e.
from column C of the "Interest Rates" spreadsheet).

TRUE - The [range_lookup] argument is set to TRUE, which tells the Vlookup function to find
the closest match to the lookup_value.
I.e. if an exact match is not found, then the function should return the closest
value below the lookup_value.
Note that this value could have been omitted from the above formula as, by default, it uses
the value TRUE.

Fix Your Vlookup Error


f you get a Vlookup error, the first step is to check that you have followed the Vlookup
Rules correctly.
If you are confident that your formula is correct, use the table below to identify the most likely
cause of your error:

Common Vlookup Errors

#N/A - Occurs if the Vlookup function fails to find a match to the supplied lookup_value.
The cause of this generally depends on the supplied [range_lookup] argument:
if [range_lookup] = TRUE - the #N/A error is likely to be because the smallest
(or is omitted) value in the left-hand column of the table_array is
greater than the supplied lookup_value.
The #N/A error could also arise if the left column of
the table_array is not in ascending order.

if [range_lookup] = FALSE - the #N/A error is likely to be because an exact


match to the lookup_value is not found in the left-
hand column of the table_array.

If you still can't understand why you are getting this Vlookup error, check out the Vlookup
#N/A Error page.
#REF! - Occurs if either:
 The supplied col_index_num argument is greater than the number of columns in the
supplied table_array.
or
 The formula has attempted to reference cells that do not exist.
This can be caused by relative referencing errors when the Vlookup is copied to other
cells.
If you need further help with this Vlookup error, check out the Vlookup #REF! Error page.

#VALUE! - Occurs if either:


 The supplied col_index_num argument is < 1 or is not recognised as a numeric value.
or
 The supplied [range_lookup] argument is not recognised as one of the logical values
TRUE or FALSE.

Incorrect - If your Vlookup function is simply returning the wrong value, check the following:
Value
Returned 1. Are the values you are searching in the left column of the table_array?
For the Vlookup function to work, the values that you are searching must be in the left
column of the table_array.

2. If the [range_lookup] argument is set to TRUE (or omitted), the function will return
the closest match below the lookup_value. For this to work correctly, the left column
of the table_array must be in ascending order.

3. Check that the col_index_num argument refers to the required column.


Remember that this is the column number counting from the first column of
the table_array. It is not necessarly the same as the spreadsheet column number.

4. If the [range_lookup] argument is set to FALSE, the Vlookup function requires an


exact match. Check that there is only one match to the lookup_value within the left
column of your table_array. Note that if there is more than one match, the Vlookup
function will use the first match that it encounters.
EXCERCISE

Study the screenshot given below representing the marks of students along with grading scheme
and answer the following questions by writing formulae in MS-Excel:
a) Write down the formulae for printing the final grade of the student against their marks with
respect to the grading scheme given.
b) Write down the formulae for counting the frequency of different grades awarded (starting from
A+ to F) in the class.
c) Write down the formulae for calculating Max Marks, Minimum Marks and Mean.

You might also like