New Tool Radar

AI for Data & Spreadsheets

How to Check Whether an AI-Written HLOOKUP Fails Because the Data Is Vertical

Check whether an AI-written HLOOKUP fails because the data is laid out vertically, not horizontally.

Schematic with three steps: Check whether the keys run across or; Test the HLOOKUP with a known value; Rewrite the lookup for the vertical layout.

HLOOKUP searches the first row of a table and returns a value from a row below it, which fits data laid out across the top, such as months in a row. When the same data is laid out down a column, with the keys in the first column, HLOOKUP searches the wrong direction and returns #N/A. An AI-written HLOOKUP on a vertical table needs VLOOKUP or XLOOKUP instead. Check the layout before the function.

What you need

  • The AI-written HLOOKUP formula
  • The lookup table, with its layout checked
  • One known lookup value and the answer it should return

Step 1: Check whether the keys run across or down

Look at the lookup table: if the keys sit in the first row, the data is horizontal and HLOOKUP fits; if the keys sit in the first column, the data is vertical and HLOOKUP does not fit.

Step 2: Test the HLOOKUP with a known value

Run the formula with a lookup value you know is in the table. If it returns #N/A, the function is searching the first row for a key that lives in the first column.

Step 3: Rewrite the lookup for the vertical layout

Replace HLOOKUP with VLOOKUP, keeping the same lookup value and the same return column counted from the left, or use XLOOKUP with the key column and the return column. Test with two known values.

Worked example: synthetic product codes down a column

The table below is a synthetic example. It shows the expected result of checking an AI-written HLOOKUP; no formula was run.

Check Value Result
Lookup value tested P-104 Known product
Keys layout Down column A Vertical table
HLOOKUP result #N/A Searches the first row
VLOOKUP result 42 Correct price for P-104

Expected result (UNTESTED). HLOOKUP returns #N/A for P-104 because the keys run down column A, not across the first row; VLOOKUP on the same table returns 42, the known price. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • HLOOKUP and VLOOKUP both need the key in the first row or column of the table; a key elsewhere returns #N/A.
  • An exact match needs FALSE as the last argument; without it, both functions use approximate match.
  • XLOOKUP replaces both functions and works in either direction, but it needs Microsoft 365 or Excel 2021 or later.
  • A table that is transposed after the formula was written flips the layout and breaks the lookup.

Sources

See all