Description
Use this function to search for a value in the top row of a table or array and return a value in the same column from a specified row. Supported in Chains.
HLOOKUP is useful for finding values across the top row of a table or array, and returning corresponding values from other rows.
Syntax
HLOOKUP(lookup_value, table_array, row_index_num, [range_lookup])
Inputs
This function accepts the following arguments:
| Name | Required | Description | Valid input |
|---|---|---|---|
lookup_value |
Yes | The value to be found in the first row of the table. | A cell reference, a cell range, a number, a text string, or a formula which results in any of these. |
table_array |
Yes | The table or array of data in which to search. | A cell range. |
row_index_num |
Yes | The row number in the table from which to retrieve the value. The first row is 1. | A positive integer, a reference to a cell containing a positive integer, or a formula which results in either of these. |
range_lookup |
No | Specifies whether to find an exact match or an approximate match. TRUE for approximate match, FALSE for exact match. If omitted, TRUE is assumed. | A boolean value (TRUE or FALSE). |
Examples
Sample data
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Item | Price | Stock | Supplier | Rating |
| 2 | Apple | 1.20 | 150 | Fresh Fruits | 4.5 |
| 3 | Banana | 0.50 | 300 | Tropical Supplies | 4.0 |
| 4 | Grape | 2.00 | 200 | Vineyard Delights | 4.7 |
| 5 | Orange | 1.00 | 250 | Citrus World | 4.3 |
Sample formulas
| Use case | Formula | Explanation and Result |
|---|---|---|
| Locate a given text string and return the equivalent value from the second row. | =HLOOKUP("Price",A1:E5,2,FALSE) |
This formula works in the following manner:
For this data set, the formula returns 1.20. |
| Locate a given text string and return the equivalent value from the fourth row. | =HLOOKUP("Stock",A1:E5,4,TRUE) |
This formula works in the following manner:
For this data set, the formula returns 200. |
| Locate a given item in the first row, then return the value from a dynamically determined row position by finding the column that contains the specified header text. | =HLOOKUP("Apple", A1:F5, MATCH("Price", A1:F1, 0), FALSE) |
This formula works in the following manner:
For this data set, the formula returns #N/A. |
| Locate a specified value in the first row of a table and return the corresponding value from the specified row; if the value isn't found, display a custom message. | =IFERROR(HLOOKUP("Pineapple", A1:F5, 3, FALSE), "Fruit not found") |
This formula works in the following manner:
For this data set, the formula returns Fruit not found. |
| Retrieve a value from a specified row of a table by looking up a value in the first row and returning the corresponding entry from the matching row. | =HLOOKUP(CELL("contents", B1), A1:F5, 3, FALSE) |
This formula works in the following manner:
For this data set, the formula returns 0.5. |
Notes
- HLOOKUP is case-insensitive. It doesn't distinguish between uppercase and lowercase letters.
- If
range_lookupis TRUE or omitted, an approximate match is returned. If FALSE, an exact match is returned. - If an exact match is not found, and
range_lookupis TRUE, HLOOKUP returns the next largest value that is less thanlookup_value. - If an exact match is not found, and
range_lookupis FALSE, HLOOKUP returns #N/A. - Ensure that the
table_arrayis sorted in ascending order when using TRUE forrange_lookupto ensure correct results.
Tips
- Use HLOOKUP when your data is organized in rows, with the values you want to look up located in the top row of the table.
- For vertical lookups, consider using VLOOKUP instead.
- To prevent errors, use IFERROR to handle cases where HLOOKUP returns #N/A.
- Consider using named ranges to make your formulas easier to read and manage.
- Combine HLOOKUP with other functions such as INDEX and MATCH for more flexible and powerful lookups.