How to use HLOOKUP in Excel with formula examples

As you probably know, Microsoft Excel has three functions to look up a value - LOOKUP, VLOOKUP and HLOOKUP - and they seem to confuse users the most. In this tutorial, we will focus on the specificities of the Excel HLOOKUP function and discuss a few formula examples that will help you use it in Excel most efficiently.

What is HLOOKUP in Excel?

The Excel HLOOKUP function is designed for horizontal lookup. More specifically, it searches for a certain value in the first row of the table and returns another value in the same column from a row that you specify.

The HLOOKUP function is available in all versions of Microsoft Excel 2016, Excel 2013, Excel 2010, Excel 2007 and lower.

Excel HLOOKUP syntax and uses

The HLOOKUP function in Excel has the following arguments:

HLOOKUP(lookup_value, table_array, row_index_num, [range_lookup])
  • Lookup_value (required) - the value to search for. It can be a cell reference, numeric value or text string.
  • Table_array (required) - two or more rows of data in which the lookup value is searched. It can be a regular range, named range or table. Lookup values should always be located in the first row of table_array.
  • Row_index_num (required) - the row number in table_array from which the value should be returned. For example, to return the matching value from the 2nd row, set row_index_num to 2, and so on.
  • Range_lookup (optional) - a logical (Boolean) value that instructs HLOOKUP to search with exact or approximate match.

    If TRUE or omitted, an approximate match is returned. What it means is if an exact match is not found, your Hlookup formula will do a non-exact match and return the next largest value that is less than lookup_value.

    If FALSE, only an exact match is returned. If no value in a specified row matches the lookup value exactly, HLOOKUP throws the #N/A error.

To make things easier to understand, you can translate Excel's HLOOKUP syntax:

HLOOKUP(lookup_value, table_array, row_index_num, [range_lookup])

into normal English:

HLOOKUP(search for this value, in this table, return a value from this row, [return an approximate or exact match])

To see how it works in practice, let's make a simple Hlookup example. Supposing you have a table with some basic information about the planets of our Solar system (please see the screenshot below). What you want is a formula that returns the diameter of the planet whose name is entered in cell B5. Source data for horizontal lookup

In our Hlookup formula, we will be using the following arguments:

  • Lookup_value is B5 - the cell containing the planet name you want to find.
  • Table_array is B2:I3 - the table where the formula will look up the value.
  • Row_index_num is 2 because Diameter is the 2nd row in the table.
  • Range_lookup is FALSE. Because the first row of our table is not sorted from A to Z, we can only look up with exact match, which works just fine in this example.

Now you put the arguments together and get the following formula:

=VLOOKUP(40, A2:B15,2) An example of HLOOKUP in Excel

3 things you should know about Excel HLOOKUP function

Whenever you do a horizontal lookup in Excel, please remember the following facts:

  1. The HLOOKUP function can only search in the top-most row of table_array. If you need to look up somewhere else, consider using an Index / Match formula.
  2. HLOOKUP in Excel is case-insensitive, it does not distinguish uppercase and lowercase.
  3. If range_lookup is set to TRUE or omitted (approximate match), the values in the first row of table_array must be sorted in ascending order (A-Z) left to right.

What is the difference between VLOOKUP and HLOOKUP in Excel?

As you already know, both functions VLOOKUP and HLOOKUP search for a lookup value. The difference is how the search is performed. As you probably noticed, the functions' names differ only in the first letter - "H" stands for horizontal, and "V" for vertical.

Hence, you use the VLOOKUP function to search is vertical lists when your lookup values are located in a column to the left of the data that you want to find.

The HLOOKUP function performs a horizontal lookup - it searches for a lookup value at the top-most row of the table and returns a value located a specified number of rows down in the same column.

The following image demonstrates the difference between Vlookup and Hlookup formulas in Excel: The difference between Vlookup and Hlookup in Excel

How to use HLOOKUP in Excel - formula examples

Now that the HLOOKUP function has started to look a bit more familiar to you, let's discuss a few more formula examples to consolidate the knowledge.

Horizontal lookup with approximate and exact match

As you already know, the HLOOKUP function in Excel can perform a lookup with exact and non-exact match depending on which value is supplied to the range_lookup argument:

  • TRUE or omitted - approximate match
  • FALSE - exact match

Please keep in mind that although we say "approximate match", any Hlookup formula searches for an exact match in the first place. But setting the last argument to FALSE allows the formula to return an approximate match (the nearest value that is less than the lookup value) if an exact match is not found; TRUE or omitted returns the #N/A error in this case.

To better illustrate the point, consider the following HLOOKUP examples.

HLOOKUP with approximate match

Supposing you have a list of planets in row 2 (B2:I2) and their temperatures in row 1(B1:I1). You want to find out which planet has a certain temperature that is input in cell B4.

You cannot rely on the off chance that your users know the lookup temperature exactly, so it makes sense to return a nearest match if an exact value in not found.

For instance, to find out the planet whose average temperature is around -340 °F, use the following formula (range_lookup set to TRUE or omitted as in this example):

=HLOOKUP(B4, B1:I2, 2)

Please remember that an approximate match requires sorting the values in the top row from smallest to largest or from A to Z, otherwise your Hlookup formula may return a wrong result.

As you can see in the screenshot below, our formula returns Uranus, one of the coldest planets in the Solar System maintaining an average of -346 degrees Fahrenheit. Excel HLOOKUP formula with approximate match

HLOOKUP with exact match

If you know the lookup value exactly, you can set the last parameter of HLOOKUP to FALSE:

=HLOOKUP(B4, B1:I2, 2, FALSE) HLOOKUP formula with exact match

On the one hand, an approximate match Hlookup is more user-friendly because it does not require sorting data in the first row. On the other hand, if the exact match is not found, an #N/A error will be returned.

Tip. Not to scare your users by N/A errors, you can embed your Hlookup formula in IFERROR and display your own message, for example:

=IFERROR(HLOOKUP(B4, B1:I2, 2, FALSE), "Sorry, nothing has been found")

How to do HLOOKUP from another worksheet or workbook

In general, h-lookup from another sheet or a different workbook means nothing else than supplying external references to your HLOOKUP formula.

To pull out matching data from a different worksheet, you specify the sheet name followed by an exclamation mark. For example:

=HLOOKUP(B$1, Diameters!$B$1:$I$2,2,FALSE) Hlookup from another worksheet

If the worksheet name contains spaces or non-alphabetical characters, enclose the name in single quotation marks, like this:

=HLOOKUP(B$1, 'Planet diameters'!$B$1:$I$2,2,FALSE)

When referencing another workbook, include the workbook name enclosed in square brackets:

=HLOOKUP(B$1, [Book1.xlsx]Diameters!$B$1:$I$2, 2, FALSE)

If you are pulling data from a closed workbook, the entire path should be specified:

=HLOOKUP(B$1, 'D:\Reports\[Book1.xlsx]Diameters'!$B$1:$I$2, 2, FALSE)

Tip. Instead of typing the workbook and worksheet names in the formula manually, you can select the cells in another sheet and Excel will add an external reference to your formula automatically.

Excel HLOOKUP with partial match (wildcard characters)

As is the case with VLOOKUP, Excel's HLOOKUP function allows using the following wildcard characters in the lookup_value argument:

  • Question mark (?) to match any single character
  • Asterisk (*) to match any sequence of characters

Wildcards come in handy when you want to pull information from a database based on some text that is part of the lookup cell's contents.

For example, you have a list of customer names in row 1 and order IDs in row 2. You want to find the order id for a specific customer but you cannot remember the customer name exactly, though you do remember it begins with "ace".

Assuming your data are in cells B1:I2 (table_array) and order numbers are in row 2 (row_index_num), the formula goes as follows:

=HLOOKUP("ace*", B1:I2, 2, FALSE)

To make the formula more flexible, you can type the lookup value in a special cell, say B4, and concatenate that cell with the wildcard character, like this:

=HLOOKUP(B4&"*", B1:I2, 2, FALSE) Hlookup example with wildcard

Notes.

  • For a wildcard HLOOKUP formula to work correctly, the range_lookup argument needs to be set to FALSE.
  • If table_array contains more than one value that meets the wildcard criteria, the first found value is returned.

Absolute and relative cell references in HLOOKUP formulas

If you are writing a formula for a single cell, you may not worry about the proper use of relative and absolute cell references, either one will do.

Copying a formula to multiple cells is a different story. In essence:

  • You should always fix table_array by using absolute cell references with the dollar sign ($) like $B$1:$I$2.
  • Typically, the lookup_value reference is relative or mixed depending on your business logic.

To make things clearer, let's have a closer look at the formula that pulls data from another sheet:

=HLOOKUP(B$1, Diameters!$B$1:$I$2,2,FALSE)

In the above formula, we use absolute cell references ($B$1:$I$2) in table_array because it should remain constant when the formula is copied to other cells.

For lookup_value (B$1), we use a mixed reference, relative column and absolute row, because our lookup values (planet names) are in the same row (row 1) but in different columns (from B to I) and the column reference should change based on a relative position of a cell where the formula in copied.

Due to the clever use of cell references, our Hlookup formula works perfectly for multiple cells: Fix the table array using absolute references.

INDEX/MATCH - a more powerful alternative to Excel HLOOKUP

As you already know, the HLOOKUP function in Excel has a number of limitations, the most significant ones are its inability to look up anywhere except for the topmost row, and the necessary to sort values when searching with approximate match.

Luckily, there exists a more powerful and versatile alternative to Vlookup and Hlookup in Excel - the liaison of INDEX and MATCH functions, which boils down to this generic formula:

INDEX (where to return a value from, MATCH (lookup value, where to search, 0))

Assuming your lookup value is in cell B7, you are looking for a match in row 2 (B2:I2), and want to return a value from row 1 (B1:I1), the formula is as follows:

=INDEX(B1:I1,MATCH(B7,B2:I2,0))

In the screenshot below, you can see 2 Hlookup formulas that search in the first and second rows, and in both cases INDEX MATCH works equally well. INDEX/MATCH  - a more flexible alternative to Excel HLOOKUP

For the detailed explanation of the formula's logic and more examples, please see INDEX MATCH as a better alternative to VLOOKUP.

How to do case-sensitive h-lookup in Excel

As mentioned in the beginning of this tutorial, the Excel HLOOKUP function is case insensitive. In situations when the character case matters, you can take the EXACT function that compares cells exactly, and put it inside the INDEX MATCH formula discussed in the previous example:

INDEX (row to return a value from, MATCH(TRUE, EXACT(row to search in, lookup value), 0))

Assuming your lookup value is in cell B4, the lookup range is B1:I1, and the return range is B2:I2, the formula takes the following shape:

=INDEX(B2:I2, MATCH(TRUE, EXACT(B1:I1,B4),0)) Example of case-sensitive horizontal lookup in Excel

Important note! It is an array formula and therefore you should press Ctrl + Shift + Enter to complete it.

The above example demonstrates my favorite but not the only possible way to do a case-sensitive Hlookup in Excel. If you are curious to know other techniques, please check out this tutorial: 4 ways to do a case-sensitive Vlookup in Excel. I think you won't have any problems with rebuilding the Vlookup formulas for a horizontal lookup.

Top 10 reasons why Excel HLOOKUP is not working

By now you already know that Hlookup is a very useful and powerful lookup function in Excel. It is also a tricky one, and because of its numerous specificities #N/A, #VALUE or #REF errors are a common sight. If your HLOOKUP formula does not work properly, most likely it's because of one of the following reasons.

1. HLOOKUP in Excel cannot look above itself

Even if you forget all other details about horizontal lookup in Excel, please remember this essential one - Hlookup can only search in the top-most row of the table. If case your lookup values reside in some other row, an N/A error is returned. To overcome this limitation, use an INDEX MATCH formula.

2. Approximate match vs. exact match

When doing a lookup in Excel, either horizontal (Hlookup) or vertical (Vlookup), in most cases you'd be searching for a particular thing, and therefore require an exact match. When searching with approximate match (range_lookup set to TRUE or omitted), remember to sort values in the first row in ascending order.

For more information and formula examples, please see Excel Hlookup with approximate and exact match.

3. The table array reference changes when copying the formula

When using multiple HLOOKUPs to retrieve information about a row of lookup values, you have to lock the table_array reference as demonstrated in Absolute and relative cell references in Hlookup formulas.

4. Inserting or deleting a new row

To understand why inserting a new row can break an Hlookup formula, remember how Excel HLOOKUP gets information about the lookup value - based on the row index number you specify.

Supposing, you want to get sales figures based on the product ID. Those figures are in row 4, so you type 4 in the row_index_num argument. But after a new row has been inserted, it becomes row 5... and your Hlookup stops working. The same problem may occur when deleting an existing row from the table.

The solution is either lock the table to prevent your users from inserting new rows, or use INDEX & MATCH instead of Hlookup. In Index/Match formulas, you specify the rows to look up and to return values from as range references, not index numbers, and Excel is smart enough to adjust those references on the fly. So, you are free to delete or insert as many columns and rows as you want without worrying about updating every formula in your worksheet.

5. Duplicates in the table

The HLOOKUP function in Excel can only return one value, which is the first value in the table that matches the lookup value.

If there are a few identical records in your table, choose one of the following solutions that best suits your needs:

6. Extra spaces

When your obviously correct Hlookup formula returns a bunch of #N/A errors, check your table and lookup value for extra spaces. You can quickly remove leading, trailing and excess in-between spaces by using Excel TRIM function or our Trim Spaces tool.

7. Numbers formatted as text

Text strings that look like numbers are another stumbling block for Excel formulas. The detailed description of this issue and possible solutions are described in Why Excel formulas may stop working.

8. Lookup value exceeds 255 characters

All Lookup functions in Excel work only as long as a lookup value is under 255 characters. A longer lookup value results in the #VALUE! error. Since the INDEX /MATCH formula is free of this limitation, use it to overcome this hurdle.

9. Full path to the lookup workbook is not specified

If you perform h-lookup from another workbook, remember to supply the full path to it. A couple of formula examples can be found here: How to do Hlookup from another worksheet or workbook.

10. Wrong arguments

It has already been highlighted more than once that HLOOKUP is a demanding function that should be treated with great care. Below are a few most common errors caused by supplying incorrect arguments:

  • If row_index_num is less than 1, the HLOOKUP function returns the #VALUE! error.
  • If row_index_num is greater than the number of rows in table_array, #REF! error is returned.
  • If you search with approximate match and your lookup_value is smaller than the smallest value in the first row of table_array, the #N/A error is returned.

Well, this is how to use HLOOKUP in Excel. Hopefully you will find this information helpful. I thank you for reading and hope to see you on our blog next week!

Download practice workbook

Excel HLOOKUP formula examples

35 comments

  1. Is it possible to use searchable dropdown formulae without macro operation . Please type formulae for data .

    List Of Employee
    John
    Marry
    Peter
    Steve
    Martha
    Harry
    Nathan
    Hanry

  2. Hi,
    can we use lookup in verticle data ?

  3. I have a worksheet with multiple members with different insurances and claims. I want to write a formula to pull all rows of claims for each member by insurance to another worksheet
    CardholderID CardholderName CardholderDOB MCOName PrescriberName PrescriberNPI Claim #
    12345678910 Sample, DERRICK 12/12/2222 United Health Medicaid MCE JOHNSON SCOTT O 12345678910 23119P017973201
    12345678910 Sample, DERRICK 12/12/2222 United Health Medicaid MCE JOHNSON SCOTT O 12345678910 23119P017973202
    12345678910 Sample, DERRICK 12/12/2222 United Health Medicaid MCE JOHNSON SCOTT O 12345678910 23119P017973203
    10987654321 Weeks, Ann 01/01/1111 Anthem Medicaid MCE NWOGU KENNETH 00000555550 23119P017973503
    I need all United Health Medicaid MCE by to bring over all of Sample, Detrick and other members who have United Health Medicaid MC but not Weeks, Ann. I have 1000 rows of data with multiple insurances and members

    • Hi! If I understand the question correctly, you can use the FILTER function to get a list of values that match certain criteria.
      The formula might look like this:

      =FILTER(A1:G100,(D1:D100="United Health Medicaid MCE")*(B1:B100<>"Weeks, Ann"))

  4. ?? class ....

  5. How do you make formula if data range is in another sheet b ut with different rows?

    =HLOOKUP(P12;Table!B1:CX2;2) this is OK .. what if data is in CX4?

    Thank you

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)