Field Guide

HLOOKUP in Excel: how the horizontal lookup works

Updated

HLOOKUP looks for a value along the top row of a table, then returns whatever sits below it in that same column, a set number of rows down. Its syntax is HLOOKUP(lookup_value, table_array, row_index_num, [range_lookup]): the value to find, the table to search, how many rows down to read the answer, and whether the match must be exact. So =HLOOKUP("Q3", A1:E3, 2, FALSE) finds Q3 along the top row and returns the value two rows down in its column.

The H is for horizontal, and that is the whole point. VLOOKUP scans the first column and returns a value to its right; HLOOKUP does the same job turned on its side, for data laid out in rows. That axis is the one thing to keep straight. If your labels run across the top of a block, HLOOKUP reads down from them; if they run down the side, you want VLOOKUP or XLOOKUP instead.

How does HLOOKUP work?

HLOOKUP takes four arguments, and only the last is optional:

Here a small table holds quarterly figures with the quarter labels running across the top:

G2
fx
=HLOOKUP(F2, A1:E3, 2, FALSE)
A B C D E F G
1 Metric Q1 Q2 Q3 Q4 Find quarter Result
2 Revenue 120 135 150 160 Q3 150
3 Units 40 46 52 55
HLOOKUP looks for Q3, the value in F2, along the top row A1:E1 and finds it in column D. row_index_num 2 returns the value one row below in that same column, D2, so the result in G2 is 150. Change the 2 to a 3 and it returns D3, the Units figure of 52.

The quarter labels sit in row 1, so that is the row HLOOKUP searches. Asking for Q3 lands on column D, and row_index_num of 2 reads down to D2, the revenue for that quarter, 150. The returned value always sits in the column HLOOKUP matched and the row you numbered, which is why getting the row number right matters as much as finding the value.

Exact match or approximate? The range_lookup argument

Most of the time you want an exact match, which means writing FALSE as the fourth argument.

=HLOOKUP(F2, A1:E3, 2, FALSE)
FALSE makes the match exact: HLOOKUP returns the value only when it finds F2 in the top row, and #N/A when it doesn't. Omit this argument, or set it to TRUE, and HLOOKUP switches to an approximate match that assumes the top row is sorted in ascending order.

Approximate mode, TRUE or the argument left off, does not need an exact hit. When it can’t find one, it settles for the next largest value that is still less than the lookup value, which is only sensible when the top row is sorted ascending. On an unsorted top row, an approximate HLOOKUP can return a plausible wrong value instead of an error, so FALSE is the safer default for the everyday case of matching a label exactly. With FALSE and a text lookup value, the wildcards ? for a single character and * for any run of characters work too.

Why does HLOOKUP return #N/A, #REF!, or #VALUE!?

Three error codes cover almost every broken HLOOKUP, and each points at a different argument.

#N/A is the common one: the lookup value isn’t in the top row. With FALSE, that means no exact match was found, and the reason is usually small.

=HLOOKUP(F2, A1:E3, 2, FALSE)
If F2 holds a value that isn't in the top row, an exact-match HLOOKUP returns #N/A. A typo, a trailing space, or a number stored as text all count as not found, even when the value looks right on screen.

The same type and space mismatches that break a VLOOKUP break an HLOOKUP, and why your VLOOKUP returns #N/A walks through each fix in detail. There’s also an approximate-mode case: when the lookup value sits under the lowest entry in the top row, HLOOKUP returns #N/A, because there’s nothing at or below it to settle for.

#REF! comes from the row number, not the value. Ask for row_index_num of 5 in a table only three rows tall and HLOOKUP returns #REF!, because that row isn’t there.

#VALUE! is the mirror mistake: a row_index_num less than 1. Count the rows in your table_array and keep the number between 1 and that count. What every error code means, and when one is safe to ignore, is in Excel’s error values, explained.

One failure throws no error at all: pointing row_index_num at the wrong row. An off-by-one number returns a real value from the wrong line, and nothing about the cell looks broken. Check the row count the same way you’d check a boundary in an IF formula, by reading back what the number actually lands on.

HLOOKUP vs VLOOKUP, INDEX MATCH, and XLOOKUP

HLOOKUP is one of four ways to look a value up, and the choice is mostly about the layout of your data and the version of Excel you’re in.

The short version

Frequently asked questions

What does the HLOOKUP function do in Excel?
HLOOKUP searches the top row of a table for a value and returns a value from the same column, a number of rows down that you choose. Its syntax is =HLOOKUP(lookup_value, table_array, row_index_num, [range_lookup]). The H stands for horizontal: where VLOOKUP scans a column, HLOOKUP scans a row, so it suits data whose labels run across the top instead of down the side.
What is the difference between HLOOKUP and VLOOKUP?
They are the same lookup on different axes. HLOOKUP searches the top row of a table and returns a value from a row below it, so use it when your comparison values run across the top. VLOOKUP searches the leftmost column and returns a value to its right, so use it when they run down the side. Microsoft frames the choice exactly that way, and on a current version of Excel XLOOKUP can do either job.
What does the range_lookup argument do in HLOOKUP?
It decides whether the match has to be exact. Set range_lookup to FALSE and HLOOKUP returns a value only when it finds the lookup value in the top row, and #N/A when it does not. Leave it out or set it to TRUE and HLOOKUP does an approximate match, which needs the top row sorted in ascending order and returns the largest value that is still less than the one you asked for.
Why does my HLOOKUP return #N/A?
An exact-match HLOOKUP returns #N/A when the lookup value is not in the top row of the table. The usual reasons are a typo, a trailing space, a number stored as text so it does not match a real number, or a range whose top row is not the one you meant to search. In approximate mode you also get #N/A when the lookup value falls below every entry in the top row, since there is nothing at or under it to match. Line the value and the range up so both sides match.
What do #REF! and #VALUE! mean in HLOOKUP?
Both come from the row number. If row_index_num points past the last row of the table, HLOOKUP returns #REF!, because you asked for a row that is not there. If it drops below 1, you get #VALUE!. Count the rows in your table_array and make sure the number lands inside it.
Should I use HLOOKUP or XLOOKUP?
On a current version of Excel, XLOOKUP is the better choice: Microsoft describes it as an improved HLOOKUP that searches in any direction and matches exactly by default. Reach for HLOOKUP when the file has to open in an older version of Excel that does not have XLOOKUP, or when you are maintaining formulas already built on it.

Catch the errors before they ship

Reviewing a change to a model? Compare the two versions in your browser and see every changed cell, formula, and value. It's free, and nothing leaves your computer.