When and How to Use VLOOKUP and HLOOKUP

Written by:  • Edited by: Tricia Goss
Updated Aug 6, 2011
• Related Guides: Microsoft | Excel | Excel Spreadsheet

The VLOOKUP and HLOOKUP functions in Microsoft Excel are powerful tools that can be used to query a lookup table, but many get confused when it comes to actually constructing formulas containing these functions. In this article, we'll explain how to do this and give concrete examples.

Better Lookup Functions

While Excel’s LOOKUP function works well in very simple tables, it does have its limitations, as we discussed in Part 1 of this series. In most cases, it is better to use the HLOOKUP or VLOOKUP functions. These two functions are basically identical – the only real difference is that VLOOKUP is used when your data is arranged in columns and HLOOKUP when your data is arranged in rows.

Since HLOOKUP and VLOOKUP are so similar, we’ll concentrate on how to use VLOOKUP for now, since it is the most common. At the end of the tutorial, we’ll show how similar results can be obtained with HLOOKUP.

Walking Through Some Examples

For this example, we’ll return to the table we used in Part 1 of this series. (Click any image for a larger view.)

Table for VLOOKUP Example
click to enlarge

Just as in Part 1, we want to construct a function that will return the applicable discount for a customer based on the number of software licenses that are purchased. The general syntax for the VLOOKUP function is

=VLOOKUP(lookup_value, table_array, col_index_num, range_lookup)

where each of the arguments of the function have the following meaning.

  • lookup_value – The value that you are looking up in the table.
  • table_array – The range of cells in which the data of the lookup table is stored.
  • col_index_num – The number of the column in the table that contains the data that is to be returned by the VLOOKUP function.
  • range_lookup – This is an optional value that only has two possible states: True or False. If the value is set to False, the VLOOKUP function will only look for exact matches to the lookup_value in the table_array. If the value is set to True, the VLOOKUP function will try to return the best match in the same manner that the basic LOOKUP function does. That is, if an exact match isn’t found, it will return the result associated with the largest value that is smaller than the lookup_value. There are a couple of additional things to note about the range_lookup.

Note: If no value is specified for the range_lookup, it will default to True. If the value of the range_lookup is True, then the first column of the table_array needs to be sorted in ascending order to ensure that the VLOOKUP function works properly.

Now, let’s see what these arguments mean in terms of our example.

Referring back to our table in the screenshot above, we want to look up whatever value is entered for Number of Licenses in cell E4. So, this would be our lookup_value. The data in our table resides in columns A and B and in row 2 through row 8. This gives us a table_array of A2:B8. We want the VLOOKUP function to return the appropriate Discount which is found in the second column of the table, making our col_index_num equal to 2. In this example, we want more than just an exact match returned, so we’ll let the range_lookup retain its default value of True and not enter anything for this argument. Thus, our resulting function becomes:

=VLOOKUP(E4, A2:B8, 2)

A screenshot of how this would appear is shown below.

VLOOKUP Standard Example
click to enlarge

Note that this function can also be modified to display a customized error message whenever invalid data is entered into the Number of Licenses field. For more information on how to make these changes to the function, see Part 2 of this series.

Corresponding HLOOKUP Example

The construction of an HLOOKUP function is identical to that of its VLOOKUP counterpart, except that column values are replaced by row values. As an example, we’ll look at the same table of information that we have been using, but this time we’ll view it in a row format.

Table in Row Format
click to enlarge

The general syntax for the HLOOKUP function is

=HLOOKUP(lookup_value, table_array, row_index_num, range_lookup)

where the arguments of the function have the same definition as those in the VLOOKUP function. The only difference here is col_index_num is replaced by row_index_num. Like its companion, row_index_num refers to the row number of the table that contains the information to be returned by the function.

The HLOOKUP function that produces the same results in this table as the VLOOKUP function in the previous example is as follows:

=HLOOKUP(B8, B1:H2, 2)

Below is a screenshot of how this function would appear in the Excel spreadsheet.

Sample HLOOKUP Function
click to enlarge

References


Comments

Showing all 10 comments
 
MURALI Sep 9, 2011 6:57 AM
how to pick scand value in vlookup
SIR PL HELP THIS ISSUE HOW TO LOOKUP IN SECAND VALUE
Rahul Dec 8, 2010 11:14 PM
Data sheet link
Please suggest me how can i link one sheet fields link into second sheet.. for example if i have a employee sheet where we have a expenduture column which shows salary also and in second sheet we have only employee names with their saving balance if i want to see the expenditure in this sheet with the help of expenditure of first sheet how i can perform it...........
Thankyou
santosh kumar samant Nov 4, 2010 2:59 AM
for MIS executive
Dear sir,
i want to master in ms excel. so what i do?
Kav Sep 13, 2010 9:40 AM
RE: VLOOKUP and HLOOKUP Functions in Microsoft Excel
Hi there,

Sounds like you need to use the SUMIF() command.

Something like:
=SUMIF(customer_name_column,"John",values_column)
Sravan May 16, 2010 6:05 AM
RE: When and How to Use VLOOKUP and HLOOKUP
SUM for a value in many rows
Can you help with this, i have a list as below:
John $52
James $23
Eric $35
John $33
TOTAL $143
How can i use a formula that count how much i need from john for example or any other name that has several entries in one cell. i tried VLOOKUP and i couldn't make it.
Tony Chaar Mar 19, 2010 12:29 PM
SUM for a value in many rows
Can you help with this, i have a list as below:
John $52
James $23
Eric $35
John $33
TOTAL $143
How can i use a formula that count how much i need from john for example or any other name that has several entries in one cell. i tried VLOOKUP and i couldn't make it.

Thank You
ranjit sahoo Sep 5, 2009 5:40 AM
need more specific example
As per the given example it,s not very much sufficient i need more sefficific example if in that
some exmaple would be use like if, then, else statement etc.. Pls if u have send me a private msg
in my email.
thanks & best regards.
ranjit sahoo
Dawood Jul 10, 2009 10:16 AM
RE: When and How to Use VLOOKUP and HLOOKUP
Hi, thanks for explanation! This tutorial also helped me much to understand how vlookup works:

http://www.myhowtoos.com/en/excel-howtoos/84-how-to-match-values-in-excel-using-vlookup
Michele McDonough Jun 17, 2009 12:10 PM
RE: nested function if hlookup and vlookup
Hi Yogesh,

I am not quite sure if I understand the scenario that you describing - do you have a more specific example that I can look at? If you want to send me a private message with the example, you can do so on my profile page. (You will need to create an account first to access the private message system.) Thanks!
yogesh kale Jun 17, 2009 11:31 AM
nested function if hlookup and vlookup
it is very difficult to search for a element in a row first using lookup_value and with the reference of this hlookup should search call back value of the element in that column using vlookup function.

simply i m unable to use a nested function for col_index_num or row_index_num.

can u help?
 
blog comments powered by Disqus
Email to a friend