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:

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:

How many cells below the formula are blocking it (0 = clear)Formula
=COUNTA(D3:D)
Row number of the first blocking cellFormula
=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:

Before: breaks as soon as anyone types in column DFormula
=ARRAYFORMULA(IF(A2:A="", , B2:B*C2:C))
After: manual value in E wins, otherwise calculateFormula
=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:

Result ends at row 500, so row 502 and below are freeFormula
=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:

In D1: header plus the whole columnFormula
={"Total"; ARRAYFORMULA(IF(A2:A="", , B2:B*C2:C))}

Good to know

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.