Answers / Question 20
ARRAYFORMULA #REF!: “Array result was not expanded because it would overwrite data” (Google Sheets)
Why ARRAYFORMULA, FILTER, QUERY and other spilling formulas show #REF! when anything sits in their output area, how to find the blocking cell fast, and how to keep manual overrides without breaking the formula.
The problem
You put one ARRAYFORMULA at the top of a column so you don't have to copy a formula down. It worked, then one day the top cell shows #REF! and the whole column goes blank. Hovering over the cell shows Array result was not expanded because it would overwrite data in D57. Often it starts right after someone typed a correction into one of the calculated cells, and you'd like to know if there's a way to let them.
Inspired by a public question on Stack Overflow. The problem above is described in our own words and the solution below is ours.
Why it happens
A formula like ARRAYFORMULA, FILTER, QUERY, UNIQUE, SORT, SPLIT or IMPORTRANGE writes its result into the cells below and to the right of itself. It's only allowed to use cells that are truly empty. If even one cell in that area holds something, Google Sheets refuses to write any of the result and shows #REF! in the formula cell instead. There's no setting that lets the formula overwrite a typed value.
With an open-ended range such as A2:A, the result is as tall as the sheet, blank rows included. So a value anywhere further down the column, even hundreds of rows below your data, blocks it.
Step 1: find what's in the way
The error message names the first blocking cell. Click it, press Delete, and check whether the error moves to another address. Common culprits:
- A value someone typed over a calculated cell (the classic case).
- The old copy-down formulas still sitting in the column from before you switched to ARRAYFORMULA.
- A cell that looks empty but holds a space, or a formula returning
"". - An unchecked checkbox: it holds FALSE, which counts as data.
- Another spilling formula whose result overlaps this one.
To see everything at once, put these in a spare cell in another column while the #REF! is showing. They assume the ARRAYFORMULA is in D2, so its result needs D3 down to be empty:
=COUNTA(D3:D)=IFERROR(MATCH(TRUE, ARRAYFORMULA(LEN(D3:D)>0), 0)+2, "No blockers")For the old copy-down formulas, select D3 down to the bottom of the sheet (click D3, then Ctrl+Shift+Down, or Cmd+Shift+Down on a Mac, until you reach the last row) and press Delete. Keep the formula in D2 only.
Step 2: let people override a value without breaking it
The cells an ARRAYFORMULA writes to aren't editable. If people need to correct some results by hand, give them their own column for it and let the formula prefer that value. Here B is quantity, C is price, E is a Manual total column people may fill in, and the formula in D2 uses E when it has a value:
=ARRAYFORMULA(IF(A2:A="", , B2:B*C2:C))=ARRAYFORMULA(IF(A2:A="", , IF(E2:E<>"", E2:E, B2:B*C2:C)))Now nobody types in column D at all. Label column E clearly and, if you like, protect column D (Data → Protect sheets and ranges) so the formula can't be overwritten by accident.
Step 3: leave room for other things below
If you need to put totals or notes under the data in the same column, give the formula a fixed end row so its result stops there:
=ARRAYFORMULA(IF(A2:A500="", , B2:B500*C2:C500))Or keep the formula in the header row so it always sits above the data, including the column title:
={"Total"; ARRAYFORMULA(IF(A2:A="", , B2:B*C2:C))}Good to know
- Sheets with rows added by Google Forms: never type into the formula column of the responses tab. Put your calculations on a second tab that reads the responses with ARRAYFORMULA or QUERY.
- Excel 365 has the same rule for dynamic arrays and calls it #SPILL!. Click the warning icon next to the cell and choose Select Obstructing Cells to jump to what's in the way.
- Sorting a range that includes the formula column can move the formula itself out of its top cell. Sort only the data columns, or use a filter view.
- In locales that use semicolons between function arguments, replace the commas in these formulas with semicolons. The
;inside{ }, which stacks the header on top of the results, stays as it is.
Formulas follow documented Google Sheets / Excel behavior; they aren't machine-tested, so try them on a copy first. Always try new automations on a copy of your sheet first.