Sub topic 12
Applying One Formula to a Whole Range with ARRAYFORMULA
Assume you can enter formulas, use A1 notation, and understand relative references. In this chapter, you will use ARRAYFORMULA to apply one formula to many rows without copying it down manually.
What ARRAYFORMULA does
ARRAYFORMULA is a Google Sheets function that lets a formula process a range of cells and return multiple results. Instead of writing a formula in every row, you write one formula in the first output cell.
Suppose a sheet has this data:
| B | C | D |
|---|---|---|
| Quantity | Price | Total |
| 2 | 10 | |
| 3 | 7 | |
| 5 | 4 |
In D2, enter:
=ARRAYFORMULA(IF(B2:B="","",B2:B*C2:C))The formula multiplies each value in column B by the value in the same row in column C. It returns the results in D2:D. The IF part keeps rows blank when column B is blank.
The references B2:B and C2:C are open-ended ranges. They include row 2 and every row below it, including rows added later.
How the formula expands
Without ARRAYFORMULA, you might enter =B2*C2 in D2 and fill it down. Each copied formula would use a different relative reference:
=B2*C2
=B3*C3
=B4*C4With ARRAYFORMULA, the range references are processed together:
=ARRAYFORMULA(B2:B*C2:C)This shorter version can work when every row contains valid values. The IF version is usually safer because it avoids displaying unwanted zeros in unused rows.
Keep the output range clear
An array result needs empty cells below and, when applicable, to the right of its starting cell. If another value blocks the result, Google Sheets may show a #REF! error with a message that the array result was not expanded.
To fix it:
- Select the output range.
- Remove values or formulas that block the expected results.
- Keep the
ARRAYFORMULAonly in its top-left output cell.
Do not place an ARRAYFORMULA in every row of the same output column. One formula should control the entire result range.
Choose ranges carefully
Open-ended ranges are convenient for growing tables, but whole-column references such as B:B can process more cells than necessary. For a small or fixed table, use a bounded range:
=ARRAYFORMULA(IF(B2:B100="","",B2:B100*C2:C100))Use matching row boundaries. A formula using B2:B100 and C2:C can produce confusing results because the ranges have different sizes.
If a source cell contains text where a number is expected, multiplication can produce an error. Use IFERROR when you want a controlled fallback:
=ARRAYFORMULA(IF(B2:B="","",IFERROR(B2:B*C2:C,"Check input")))This preserves blank rows and displays Check input for invalid nonblank rows.
Exercise
In D2, write one formula that multiplies quantities in B2:B by prices in C2:C, leaves rows blank when B is empty, and shows "Invalid" for other calculation errors.
Show answer
=ARRAYFORMULA(IF(B2:B="","",IFERROR(B2:B*C2:C,"Invalid")))