How to use a vlookup function in excel


VLOOKUP Function

The VLOOKUP function is a premade function in Excel, which allows searches across columns.

It is typed =VLOOKUP and has the following parts:

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

Note: The column which holds the data used to lookup must always be to the left.

Note: The different parts of the function are separated by a symbol, like comma , or semicolon ;

The symbol depends on your Language Settings.

Lookup_value: Select the cell where search values will be entered.

Table_array: The table range, including all cells in the table.

Col_index_num: The data which is being looked up. The input is the number of the column, counted from the left:

How to use a vlookup function in excel

Range_lookup: TRUE if numbers (1) or FALSE if text (0).

Note: Both 1 / 0 and True / False can be used in Range_lookup.

How to use the VLOOKUP function.

How to use a vlookup function in excel


  1. Select a cell (H4)
  2. Type =VLOOKUP
  3. Double click the VLOOKUP command
  4. Select the cell where search value will be entered (H3)
  5. Type (,)
  6. Mark table range (A2:E21)
  7. Type (,)
  8. Type the number of the column, counted from the left (2)
  9. Type True (1) or False (0) (1)
  10. Hit enter
  11. Enter a value in the cell selected for the Lookup_value H3(7)

Let's have a look at an example!

Use the VLOOKUP function to find the Pokemon names based on their ID#:

How to use a vlookup function in excel

H4 is where the search result is displayed. In this case, the Pokemons names based on their ID#.

How to use a vlookup function in excel

How to use a vlookup function in excel

H3 selected as lookup_value. This is the cell where the search query is entered. In this case the Pokemons ID#.

How to use a vlookup function in excel

How to use a vlookup function in excel

The range of the table is marked at table_array, in this example A2:E21.

How to use a vlookup function in excel

The number 2 is entered as col_index_number. This is the second column from the left and is the data that is being looked up.

How to use a vlookup function in excel

An illustration for selecting col_index_number 2.

How to use a vlookup function in excel

Ok, so next - 1 (True) is entered as range_lookup. This is because the most left column has numbers only. If it was text, 0 (False) would have been used.

How to use a vlookup function in excel

Good job! The function returns the #N/A value. This is because there have not been entered any value to the Search ID# H3.

Let us feed a value to it, type H3(7):

How to use a vlookup function in excel

Have a look at that! The VLOOKUP function has successfully found the Pokemon Squirtle which has the ID# 7.

One more time, type (H3)4:

How to use a vlookup function in excel

It still works! The function returned Charmanders name, which has 4 as its ID#. That's great.



VLOOKUP is an Excel function to get data from a table organized vertically. Lookup values must appear in the first column of the table passed into VLOOKUP.  VLOOKUP supports approximate and exact matching, and wildcards (* ?) for partial matches. 

Vertical data | Column Numbers | Only looks right | Matching Modes | Exact Match | Approximate Match | First Match | Wildcard Match | Two-way Lookup | Multiple Criteria | #N/A Errors | Videos

Introduction

VLOOKUP is probably the most famous function in Excel, for reasons both good and bad. On the good side, VLOOKUP is easy to use and does something very useful. For new users in particular, it is immensely satisfying to watch VLOOKUP scan a table, find a match, and return a correct result. Using VLOOKUP successfully is a rite of passage: from beginner to skilled Excel user.

On the bad side, VLOOKUP is limited and has dangerous defaults. Unlike INDEX and MATCH (or XLOOKUP), VLOOKUP needs a complete table with lookup values in the first column. This makes it hard to use VLOOKUP with multiple criteria. In addition, VLOOKUP's default matching behavior makes it easy to get incorrect results. Fear not. The key to using VLOOKUP successfully is mastering the basics. Read on for a complete overview.

Arguments

VLOOKUP takes four arguments: lookup_value, table_array, column_index_num, and range_lookup. Lookup_value is the value to look for, and table_array is the range of vertical data to look inside. The first column of table_array must contain the lookup values to search. The column_index_num argument is the column number of the value to retrieve, where the first column of table_array is column 1. Finally, range_lookup controls match behavior. If range_lookup is TRUE, VLOOKUP will perform an approximate match. If range_lookup is FALSE, VLOOKUP will perform an exact match. Important: range_lookup is optional and defaults to TRUE, so VLOOKUP will perform an approximate match by default. See below for more information on matching.

V is for vertical

The purpose of VLOOKUP is to look up information in a table like this:

How to use a vlookup function in excel

With the Order number in column B as the lookup_value, VLOOKUP can get the Cust. ID, Amount, Name, and State for any order. For example, to get the name for order 1004, the formula is:

=VLOOKUP(1004,B5:F9,4,FALSE) // returns "Sue Martin"

To look up horizontal data, you can use HLOOKUP, INDEX and MATCH, or XLOOKUP.

VLOOKUP is based on column numbers

When you use VLOOKUP, imagine that every column in the table_array is numbered, starting from the left. To get a value from a given column, provide the number for column_index_num. For example, the column index to retrieve the first name below is 2:

How to use a vlookup function in excel

By changing only column_index_num, you can look up columns 2, 3, and 4:

=VLOOKUP(H3,B4:E13,2,FALSE) // first name
=VLOOKUP(H3,B4:E13,3,FALSE) // last name
=VLOOKUP(H3,B4:E13,4,FALSE) // email address

Note: normally, we would use an absolute reference for H3 ($H$3) and B4:E13 ($B$4:$E$13) to prevent these from changing when the formula is copied. Above, the references are relative to make them easier to read.

VLOOKUP only looks right

VLOOKUP can only look to the right. In other words, you can only retrieve data to the right of the column that holds lookup values:

How to use a vlookup function in excel

To lookup values to the left, see INDEX and MATCH, or XLOOKUP.

Match modes

VLOOKUP has two modes of matching, exact and approximate, controlled by the fourth argument, range_lookup. The word "range" in this case refers to "range of values" – when range_lookup is TRUE, VLOOKUP will match a range of values rather than an exact value. A good example of this is using VLOOKUP to calculate grades. When range_lookup is FALSE, VLOOKUP performs an exact match, as in the example above.

Important:  range_lookup is optional defaults to TRUE. This means approximate match is the default mode, which can be dangerous. Set range_lookup to FALSE to force exact matching:

=VLOOKUP(value,table,col_index) // approximate match (default)
=VLOOKUP(value,table,col_index,TRUE) // approximate match
=VLOOKUP(value,table,col_index,FALSE) // exact match

Tip: always supply a value for range_lookup as a reminder of expected behavior.

Note: You can also supply zero (0) for an exact match, and 1 for approximate match.

Exact match example

In most cases, you'll probably want to use VLOOKUP in exact match mode. This makes sense when you have a unique key to use as a lookup value, for example, the movie title in this data:

How to use a vlookup function in excel

The formula in H6 to find Year, based on an exact match of movie title, is:

=VLOOKUP(H4,B5:E9,2,FALSE) // FALSE = exact match

Video: How to use VLOOKUP for exact match

Approximate match example

When you want the best match, not necessarily an exact match, you'll want to use approximate mode. For example, below we want to look up a commission rate in the table G5:H10. The lookup values come from column C. In this example, we need to use VLOOKUP in approximate match mode, because in most cases an exact match will never be found. The VLOOKUP formula in D5 is configured to perform an approximate match by setting the last argument to TRUE:

How to use a vlookup function in excel

=VLOOKUP(C5,$G$5:$H$10,2,TRUE) // TRUE = approximate match

VLOOKUP will scan values in column G for the lookup value. If an exact match is found, VLOOKUP will use it. If not, VLOOKUP will "step back" and match the previous row. This means table_array must be sorted in ascending order by lookup value to use approximate match.

Caution: If range_lookup is omitted or TRUE and table_array is not sorted by the first column in ascending order, VLOOKUP may return incorrect or unexpected results.

Video: How to use VLOOKUP for approximate match

First match only

In the case of duplicate matching values, VLOOKUP will find the first match. In the screen below, VLOOKUP is configured to find the price for the color "Green". There are three rows with the color Green, and VLOOKUP returns the price in the first row, $17. The formula in cell F5 is:

=VLOOKUP(E5,B5:C11,2,FALSE) // returns 17

How to use a vlookup function in excel

Tip: To retrieve multiple matches in a lookup operation, see the FILTER function.

Wildcard match

The VLOOKUP function supports wildcards, which makes it possible to perform a partial match on a lookup value. For instance, you can use VLOOKUP to retrieve information from a table with a partial lookup_value and wildcard. To use wildcards with VLOOKUP, you must use exact match mode by providing FALSE for range_lookup. In the screen below, the formula in H7 retrieves the first name, "Michael", after typing "Aya" into cell H4. Notice the asterisk (*) wildcard is concatenated to the lookup value inside the VLOOKUP formula:

=VLOOKUP($H$4,$B$5:$E$104,2,FALSE)

How to use a vlookup function in excel

Read a more detailed explanation here.

Video: How to use VLOOKUP for wildcard matches.

Two-way lookup

Inside the VLOOKUP function, column_index_num is normally hard-coded as a static number.  However, you can also create a dynamic column index by using the MATCH function to locate the needed column. This technique allows you to create a dynamic two-way lookup, matching on both rows and columns. In the screen below, VLOOKUP is configured to perform a lookup based on Name and Month. The formula in H6 is:

=VLOOKUP(H4,B5:E13,MATCH(H5,B4:E4,0),0)

How to use a vlookup function in excel

For more details, see this example.

Video: Two-way match with VLOOKUP.

Note: In general, INDEX and MATCH is a more flexible way to perform two-way lookups.

Multiple criteria

The VLOOKUP function does not handle multiple criteria natively. However, you can use a helper column to join multiple fields together, and use these fields like multiple criteria inside VLOOKUP.  In the example below, Column B is a helper column that concatenates first and last names together with this formula:

=C5&D5 // helper column

VLOOKUP is configured to do the same thing to create a lookup value. The formula in H6 is:

=VLOOKUP(H4&H5,B5:E13,4,0)

How to use a vlookup function in excel

For details, see this example. For a more advanced, flexible approach, see this example.

Note: INDEX and MATCH and XLOOKUP are better for lookups based on multiple criteria.

VLOOKUP and #N/A errors

If you use VLOOKUP you will inevitably run into the #N/A error. The #N/A error means "not found". For example, in the screen below, the lookup value "Toy Story 2" does not exist in the lookup table, and all three VLOOKUP formulas return #N/A:

How to use a vlookup function in excel

The #N/A error is useful because tells you something is wrong. The reason for #N/A might be:

  • The lookup value does not exist in the table
  • The lookup value is misspelled, or contains extra space
  • Match mode is exact, but should be approximate
  • The table range is not entered correctly
  • You are copying VLOOKUP, and the table reference is not locked

To "trap" the NA error and return a different value, you can use the IFNA function like this:

How to use a vlookup function in excel

The formula in H6 is:

=IFNA(VLOOKUP(H4,B5:E9,2,FALSE),"Not found")

The message can be customized as desired. To return nothing (i.e. to display a blank result) when VLOOKUP returns #N/A you can use an empty string ("") like this:

=IFNA(VLOOKUP(H4,B5:E9,2,FALSE),"") // no message

You can also use the IFERROR function to trap VLOOKUP #N/A errors. However, be careful with IFERROR, because it will catch any error, not just the #N/A error.

Read more: VLOOKUP without #N/A errors 

Video: What to do when VLOOKUP returns #N/A

More about VLOOKUP

  • More VLOOKUP examples
  • VLOOKUP videos
  • 23 tips for using VLOOKUP

Other notes

  • VLOOKUP performs an approximate match by default.
  • VLOOKUP is not case-sensitive.
  • Range_lookup controls the match mode. FALSE = exact, TRUE = approximate (default).
  • If range_lookup is omitted or TRUE or 1: 
    • VLOOKUP will match the nearest value less than the lookup_value.
    • VLOOKUP will still use an exact match if one exists.
    • The column 1 of table_array must be sorted in ascending order.
  • If range_lookup is FALSE or zero:
    • VLOOKUP performs an exact match.
    • Column 1 of table_array does not need to be sorted.

How use VLOOKUP step by step?

How to use VLOOKUP in Excel.
Step 1: Organize the data. ... .
Step 2: Tell the function what to lookup. ... .
Step 3: Tell the function where to look. ... .
Step 4: Tell Excel what column to output the data from. ... .
Step 5: Exact or approximate match..

How do I do a VLOOKUP between two spreadsheets?

How to use the formula to Vlookup across sheets.
Write down all the lookup sheet names somewhere in your workbook and name that range (Lookup_sheets in our case)..
Adjust the generic formula for your data. ... .
Enter the formula in the topmost cell (B2 in this example) and press Ctrl + Shift + Enter to complete it..