Sub topic 6
Returning several columns at once
This chapter assumes you can enter and copy formulas, use absolute references such as $E$2, and have Excel for Microsoft 365, Excel 2021 or later, or Excel for the web. You should also know how a basic exact-match XLOOKUP works, including its default behavior and the if_not_found argument.
One match, many values
So far, the return_array argument has been a single column. It can also span several columns. XLOOKUP finds the matching position once, then returns the whole row of values from that position in the return array.
Suppose A2:D10 holds an employee table. Column A has the employee ID, B the name, C the department, and D the salary. The formula below looks up the ID in E2 and returns B, C and D for that row:
=XLOOKUP(E2, A2:A10, B2:D10)Enter it once in a single cell, such as F2. The result has three values, so Excel spills them into F2, G2 and H2. You don't copy the formula across.
How spilling works
A spill is Excel's way of showing a result that is larger than one cell. The formula lives in the first cell, called the anchor. The other cells show a pale blue border when you select any of them. You can't edit or overwrite them directly, only the anchor.
flowchart LR
A["Lookup value in E2"] --> B["Find position in A2:A10"]
B --> C["Take that row from B2:D10"]
C --> D["Spill into F2, G2, H2"]The diagram above is for reference only. The version below follows the required format.
The shape of the result follows the shape of the return array:
| Return array | Result |
|---|---|
| One column, such as `C2:C10` | One value |
| Several columns, such as `B2:D10` | One row of values, spilled across |
| A row of values, with a lookup across a row | One column of values, spilled down |
The last case happens when your data is laid out horizontally. The lookup array is a single row, such as B1:J1, and the return array is B2:J4. XLOOKUP then returns the matching column from all three rows, spilled downward.
Common errors
#SPILL! appears when something blocks the spill range. If G2 already contains a value, the formula in F2 can't spill into it. Clear the blocking cells and the result appears. Text, a space, or a formatted merged cell can all cause this.
Mismatched sizes. The lookup array and return array must have the same number of rows when you look up vertically. A2:A10 with B2:D9 returns #VALUE!. The number of columns in the return array can differ, because that is what controls how many values spill.
Values you didn't want. A return array that is wider than you need returns extra columns. If you only want columns B and D, either use two separate formulas or choose a return array that contains only the columns you need.
Older Excel. Excel 2019 and earlier don't have XLOOKUP or spilling. A file that uses them shows errors in those versions.
Adding a missing-value message
You can combine multi-column return with if_not_found. When the ID is missing, the text message appears in the anchor cell only, because it is a single value:
=XLOOKUP(E2, A2:A10, B2:D10, "Not found")If you want the message to appear across all three cells, you can't do this with a plain text value. The spill holds one value in this case, so keep the message short and place it where the reader will see it.
Referring to the spilled result
You can refer to the whole spilled range using the spill operator # after the anchor cell. For example, =SUM(F2#) adds all values the formula in F2 returns. This also works when the spill grows or shrinks, as it would if the return array changes size.
Exercise
A2:A10 contains product codes, B2:B10 product names, C2:C10 prices and D2:D10 stock counts. Write one formula in F2 that looks up the code in E2 and returns the name, price and stock count, showing "Unknown code" if the code is missing. Where do the results appear?
Show answer
Use =XLOOKUP(E2, A2:A10, B2:D10, "Unknown code"). The name appears in F2, the price in G2 and the stock count in H2, because the formula spills across three columns. G2 and H2 must be empty, or the result is #SPILL!. If the code is missing, "Unknown code" appears in F2 only.