Excel Lessons

HLOOKUP in Excel, and when to use XLOOKUP instead

HLOOKUP searches the top row of a table and returns a value from a row below it. Its four arguments, where it breaks, and the XLOOKUP that replaces it.

Published . 5 min read.

By Ali, Founder, Excel Lessons

HLOOKUP searches the top row of a table for a value. Then it returns the value from a row below it, in the same column. It is VLOOKUP turned on its side.

You meet it when a table runs across the page. A courier sends a rate card with the zones along the top. You need the price for Zone 3, and the zone is in G2.

Row A B C D E
1 ServiceZone 1Zone 2Zone 3Zone 4
2 Standard4.26.59.814
3 Express7.911.516.2523
4 Days2357

The four arguments

The shape is =HLOOKUP(lookup_value, table, row_number, FALSE).

  • lookup_value is what to find in the top row. Here it is G2.
  • table is the whole block, top row included. Here it is B1:E4.
  • row_number counts rows inside that block. Row 1 is the top row, so Standard is 2.
  • FALSE asks for an exact match. Always type it.

=HLOOKUP(G2,B1:E4,2,FALSE) gives 9.8. That is the Standard price for Zone 3.

=HLOOKUP("Zone 4",B1:E4,4,FALSE) gives 7. That is the number of days for Zone 4, from the fourth row.

The table can start in column A as well. =HLOOKUP(G2,A1:E4,2,FALSE) also gives 9.8. The labels in column A do no harm, and the row numbers stay the same.

Three ways it gives a wrong answer

HLOOKUP is short to write. The trouble is that it can be wrong and still show a number. These are the three cases to watch for.

1. The FALSE is missing

Leave out the last argument and HLOOKUP does an approximate match. It looks for the nearest value that is not bigger than yours.

There is no Zone 5 on the card. =HLOOKUP("Zone 5",B1:E4,2) gives 14, the Zone 4 price. Nothing tells you the zone was not found.

With FALSE, =HLOOKUP("Zone 5",B1:E4,2,FALSE) gives #N/A. That is the answer you want, because it is true.

An approximate match is only right for bands, like prices by weight. The top row must then be sorted from small to large. The approximate match article covers that case.

2. Somebody inserts a row

Next month the courier adds an Economy service. Somebody inserts it as a new row 2. The table range grows to B1:E5 by itself, but the 2 in the formula does not change.

Row A B C D E
1 ServiceZone 1Zone 2Zone 3Zone 4
2 Economy3.14.87.210.5
3 Standard4.26.59.814
4 Express7.911.516.2523
5 Days2357

The formula is now =HLOOKUP(G2,B1:E5,2,FALSE). It gives 7.2, the Economy price. Every Standard parcel in your sheet is now priced too low.

This is the same problem VLOOKUP has with an inserted column. A typed number does not move when the table moves.

3. The row is counted from the sheet

The row number counts from the top of the range you gave, not from row 1 of the sheet. Say the card sits in B10:E13. Standard is still row 2 of the table, not row 11.

Ask for a row past the bottom of the table and you get an error. That at least is honest. =HLOOKUP(G2,B1:E4,5,FALSE) gives #REF!, because the table has only 4 rows.

Let MATCH find the row

You can stop the inserted row from breaking HLOOKUP. MATCH finds the row number from the label in column A.

=HLOOKUP(G2,A1:E4,MATCH("Express",A1:A4,0),FALSE) gives 16.25. MATCH finds Express in position 3.

After the Economy row goes in, the ranges grow to A1:E5 and A1:A5. MATCH now says 4, and the answer is still 16.25.

Both ranges start in row 1 here. That is what keeps the MATCH number and the HLOOKUP row number in step.

XLOOKUP does the same job with less to break

XLOOKUP takes the row to search and the row to return as two separate ranges. There is no row number to count.

=XLOOKUP(G2,B1:E1,B2:E2) gives 9.8. B1:E1 is the row of zones. B2:E2 is the row of Standard prices.

Insert the Economy row and the second range moves down to B3:E3 by itself. The answer stays 9.8.

=XLOOKUP("Zone 5",B1:E1,B2:E2,"No such zone") shows your own text when nothing matches. Exact match is the default, so there is no FALSE to forget.

XLOOKUP needs Excel 2021 or later, Microsoft 365 or Excel for the web. In Excel 2019 and older it shows #NAME?. HLOOKUP works in every version.

Which one to write

Use XLOOKUP, unless the file must open in Excel 2019 or older. Then use HLOOKUP with MATCH for the row, and always type FALSE.

If the table is yours, think about turning it round. Copy it, then use Paste Special and tick Transpose. With the zones down the side, VLOOKUP and filters work the usual way. Most data grows downwards, and most tools expect it to.

For more on the two, read XLOOKUP vs VLOOKUP.

Questions people ask

What is the difference between VLOOKUP and HLOOKUP?

Only the direction. VLOOKUP searches down the first column and returns a column to the right. HLOOKUP searches across the top row and returns a row below. The arguments are the same.

Can HLOOKUP search a row that is not the top one?

No. It only searches the top row of the range you give. To search another row, use XLOOKUP, or INDEX with MATCH.

Does HLOOKUP care about capital letters?

No. =HLOOKUP("zone 3",B1:E4,3,FALSE) finds Zone 3 and gives 16.25. Upper and lower case count as the same.

Where can I practise it?

In the HLOOKUP lesson below, then XLOOKUP. Each lesson is a real sheet you type into, and each answer is checked when you press Enter. The VLOOKUP exercises use the same arguments the other way round.

Related articles