Menu

HLOOKUP in Excel: Look Up Across a Row, with Examples

=HLOOKUP("Mar",A1:E3,2,FALSE) looks for Mar in the first row of A1:E3 and returns the value from the second row of the same column. Exact and approximate match, and when XLOOKUP is the better choice.

Every sheet on this page is live: change a number or a formula and it recalculates.

=HLOOKUP("Mar",A1:E3,2,FALSE) looks for Mar in the first row of A1:E3 and returns the value from the second row of the same column. It is VLOOKUP turned on its side, for tables where the labels run across the top.

Sales of one month
B6
ABCDE
1MonthJanFebMarApr
2Sales4,2003,9004,8005,100
3Costs2,6002,5002,9003,000
4
5MonthMar
6Sales4,800
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

B6 searches row 1 for Mar, finds it in column D, and returns row 2 of that column: 4,800. Pick Apr in B5 for 5,100, or change the 2 in the formula to 3 for the costs.

HLOOKUP syntax

=HLOOKUP(lookup_value, table_array, row_index_num, [range_lookup])
  • lookup_value: what to find in the first row of the table.
  • table_array: the table. HLOOKUP only searches its top row.
  • row_index_num: which row to return, counting the top row as 1. A number larger than the table is tall gives #REF!; 0 gives #VALUE!.
  • range_lookup: FALSE for an exact match. TRUE or nothing for an approximate match on a sorted row.

The match ignores case (mar finds Mar), and with FALSE the lookup value can use the wildcards * and ?. A value not in the first row returns #N/A.

Approximate match across a row

With TRUE, HLOOKUP finds the largest header less than or equal to the lookup value. The first row must be sorted from left to right in ascending order.

Shipping cost by weight
B5
ABCDE
1Weight from (kg)02510
2Cost$4.50$6.00$9.50$14.00
3
4Parcel (kg)7
5Cost$9.50
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

7 kg is not a header. The largest header not above it is 5, so B5 returns 9.50.ChangeB4to1.5for9.50. Change B4 to 1.5 for 4.50 or to 12 for $14.00. The table in the formula is B1:E2, not A1:E2: it starts at the first weight so the text label in A1 is not part of the sorted row.

XLOOKUP across a row

In Excel 2021 and Microsoft 365, XLOOKUP replaces HLOOKUP. It takes the row to search and the row to return as two ranges, so there is no row number to count, and a return range several rows tall brings back the whole column.

The same lookup with XLOOKUP
B7
ABCDE
1MonthJanFebMarApr
2Sales4,2003,9004,8005,100
3Costs2,6002,5002,9003,000
4Profit1,6001,4001,9002,100
5
6MonthFeb
7Figures3,900
82,500
91,400
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

One formula in B7 spills the three figures for Feb down B7:B9: 3,900, 2,500 and 1,400. If B8 or B9 held something, B7 would show #SPILL!. The XLOOKUP page covers its other options, such as a not-found message and the last match.

Turn the table instead: TRANSPOSE

Sometimes the better fix is a vertical copy of the table. =TRANSPOSE(A1:D3) returns the same cells with rows and columns swapped, and it stays linked to the original. VLOOKUP, FILTER and charts then work on it as usual.

A vertical copy of a horizontal table
A5
ABCD
1MonthJanFebMar
2Sales4,2003,9004,800
3Costs2,6002,5002,900
4
5MonthSalesCosts
6Jan4,2002,600
7Feb3,9002,500
8Mar4,8002,900
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

A5 spills a 4 by 3 block: months down the side, Sales and Costs across the top. Change Feb's sales in C2 to 4100 and the copy follows. For a one-off copy without a formula, select the table, copy it, then use Home > Paste > Paste Special and tick Transpose.

Practice: costs of a month

Monthly figures
B6
ABCDE
1MonthJanFebMarApr
2Sales4,2003,9004,8005,100
3Costs2,6002,5002,9003,000
4
5MonthApr
6Costs
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Your turn: In B6, use HLOOKUP to return the costs of the month in B5.

Frequently Asked Questions

What is the difference between VLOOKUP and HLOOKUP?

VLOOKUP searches down the first column of a table and returns a value from a column to the right. HLOOKUP searches across the first row and returns a value from a row below. The arguments are the same, with a row index in place of the column index.

What is the row index in HLOOKUP?

The number of the row to return, counted from the first row of the table, which is row 1. In =HLOOKUP("Mar",A1:E3,3,FALSE), 3 means the third row of A1:E3. A number larger than the table is tall returns #REF!.

Can XLOOKUP replace HLOOKUP?

Yes. XLOOKUP works in either direction: =XLOOKUP("Mar",B1:E1,B2:E2) searches a row and returns from another row. It needs Excel 2021 or Microsoft 365.

Why does HLOOKUP return #N/A?

The lookup value is not in the first row of the table: a typo, an extra space, a number stored as text, or a value that sits in another row. With TRUE as the last argument, a value smaller than the first header also returns #N/A.

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED