HLOOKUP Function in Excel
The Horizontal lookup function, HLOOKUP in excel is used to find the specific value in a row for the table that is arranged horizontally.
- The Horizontal lookup function (Excel HLOOKUP) is used to find a specific value in a row for a table arranged horizontally.
- On the other hand, if the table data is arranged vertically, then the VLOOKUP (vertical lookup) function is used.
- In the HLOOKUP function, a lookup value is provided and is searched in a table or array of values.
- It returns a value in the same column from a specified row, which must be within the table or array.
- If you're still unclear about how HLOOKUP works, consider looking at a few examples in this tutorial that should make things clear.
Syntax of HLOOKUP function
HLOOKUP(lookup_value, table_array, row_index_num, [range_lookup])
Before explaining these arguments, let us look at the HLOOKUP function in action that will make you easily understand that.
A simple example of Excel VLOOKUP
Our example sheet contains the Names of students, scores in three subjects, and their total. The demo data is arranged horizontally as shown below:
Now suppose, we want to retrieve the total marks of “Jhony”. See how we can do this by using the HLOOKUP function:
The HLOOKUP formula:
=HLOOKUP("Total",A1:E5,4,FALSE)
The resultant sheet:
Now, let me explain the arguments of the HLOOKUP function on the basis of this example.
Argument | Explanation |
lookup_value | The lookup_value is required. In the example, the Total is the lookup_value. This is the value to be found in the first row of the table. In our example, the first row contains the headers, and “Total” is one of those. You may also use cell references there. |
table_array | The second argument is the table_array which is also required. This specifies the area in which lookup_value is required to be found. In our example, A1:E5 is the table_array. You may also use the range name there. |
row_index_num | The third argument is row_index_num, required as well. This is the number of rows in the table_array. Do not mix it up with the actual row number in the Excel table. As such, your table_array may be the subset of the Excel table. In our example case, we used 5 value that is related to the “Johny” record. |
range_lookup | The final argument is range_lookup and this is optional. But you should generally use it. It defaults to True; which means find the approximate match. The FALSE logical value means finding the exact match. I will explain this further in the coming section with an example, especially the TRUE value. |
Note: The HLOOKUP function is case-insensitive. That means, “Bio” and “bio” are taken as same.
The example of using cell reference in HLOOKUP Excel function
Rather than using the hard code value as used in the previous example “Total”, we may use a cell reference there as well. That approach enables us using the lookup_up value dynamically.
In the context of our example, this can be useful for not only finding the Total but individual subject marks as well. For example, I want to search the marks in Chemistry, and Biology along with the total for Haynes. See the formula and sheet for an idea how you can do this:
The HLOOKUP formula:
The results as I entered different texts in cell C8:
For Physics:
For Biology:
For Total:
Using the wildcard example in HLOOKUP function
You may also use the wildcards in HLOOKUP function. The supported wildcard characters are:
- “*” The asterisk matches any sequence of characters.
- “?” For matching the single character
To demonstrate that, I am moving ahead with the above example. I will just enter the “Phy*” and “Che*” and see how “*” wildcard works in HLOOKUP:
For “Phy*”
Note that, the same formula is used as in above example. We just entered the wildcard in C8 cell.
The example of ‘?’ wildcard
I used Bio???? and see the output:
If I entered Bio??, an error would have produced.
The #NA error and resolving this in HLOOKUP
The HLOOKUP function produces an error if a given search term is not found in the table_array. For example, I entered "Math" in our example sheet and see the output:
You may display a descriptive message by using IFERROR function with HLOOKUP as follows:
The IFERROR/HLOOKUP formula:
=IFERROR(HLOOKUP(C8,A1:E5,2,FALSE), "Please enter available subjects")
You see, now it displayed “Please enter available subjects!” as I entered Math.
Using True value for Range_Lookup argument example
Just to remind, using TRUE value means to return the approximate match. If you are using the TRUE value then make sure that values in the first row of table_array must be in ascending order. Otherwise, it may return incorrect results.
Note: TRUE is the default value. If you omit this, the VLOOKUP function will use TRUE.
First, have a look at the example of using the same order as in above examples with TRUE value:
The Formula:
=HLOOKUP(C8,A1:E5,2,TRUE)
You can match the returned result which is incorrect. It displayed the marks of Biology while I entered Physics.
See the outputs as I re-ordered the subjects in ascending order and changed the range a bit:
=HLOOKUP(C8,B1:F5,2,TRUE)
The results:
For “mis”:
Generally, you will use the exact match option by using FALSE value in the HLOOKUP formula.