Sub topic 11
One formula for the whole column with ARRAYFORMULA
You have written an IF formula that grades one row and copied it down a column. This chapter shows how to replace those copies with a single formula that fills the whole column and keeps filling as rows are added.
This chapter assumes you can write a basic IF formula, use A1-style references, and read comparisons such as B2>=50. It also assumes you know how relative and absolute references behave when you copy a formula.
Why copying a formula down has limits
Copying =IF(B2>=50, "Pass", "Fail") down a column works, but it has costs:
- New rows have no formula until someone copies it down. This is a common problem with sheets fed by Google Forms or by pasted data.
- Anyone can overwrite one result cell with a typed value, and the column quietly becomes inconsistent.
- If you change the logic, you must copy the new formula over every row again.
ARRAYFORMULA puts the logic in one cell. That cell returns a whole column of results, and Sheets fills them into the cells below it.
What an array formula does
A normal IF formula takes single values. If you give it a range, it uses only the first cell of that range. Try this in D2:
=IF(B2:B>=50, "Pass", "Fail")You get one result, for B2 only. Nothing spills down the column.
ARRAYFORMULA tells Sheets to run the formula once for every row of the range and return all the results together. Wrap the same formula like this:
=ARRAYFORMULA(IF(B2:B>=50, "Pass", "Fail"))Now D2 holds the formula, and D3, D4 and the cells below show the other results. Those lower cells have no formula of their own. They are the spilled output of D2, and Sheets shows them in the same way as normal cell values.
You can also type the formula normally and press Ctrl+Shift+Enter (Cmd+Shift+Enter on a Mac). Sheets then adds the ARRAYFORMULA(...) wrapper for you.
Worked example: a grade column that grows
Suppose the sheet looks like this, with headers in row 1:
| Row | A (Name) | B (Score 1) | C (Score 2) | D (Result) |
|---|---|---|---|---|
| 1 | Name | Score 1 | Score 2 | Result |
| 2 | Amara | 72 | 65 | |
| 3 | Ben | 48 | 80 | |
| 4 | Chloe | 55 | 51 | |
| 5 |
Put this in D2:
=ARRAYFORMULA(IF(A2:A="", "", IF(B2:B>=50, "Pass", "Fail")))This is the formula from the earlier chapter on blank checks, with two changes. A2:A replaces A2, and ARRAYFORMULA wraps everything. The result is Pass, Fail, Pass in D2:D4, and nothing in D5 and below.
Three details matter here:
- The range has no end row.
A2:Ameans "from A2 to the bottom of column A". When you type a name in A5, D5 fills in without any action from you. - The blank check is required. A range like
B2:Bincludes the empty cells below your data. An empty cell compares as 0 in a numeric comparison, soB6>=50is FALSE and the formula would write "Fail" in every empty row. TheA2:A=""test stops that by returning an empty string for rows with no name. - Every range must have the same height.
A2:AandB2:Bboth run to the bottom of their column, so they line up. MixingA2:AwithB2:B20can cause a size mismatch error or skipped rows.
References inside an array formula
Absolute references still work the way you expect. A single cell such as $F$1 is treated as one value that applies to every row:
=ARRAYFORMULA(IF(A2:A="", "", IF(B2:B>=$F$1, "Pass", "Fail")))Change the pass mark in F1 and every result updates. You do not need $ signs on the ranges, because the formula is never copied. The $ on $F$1 is mainly a safeguard in case you later copy or move the formula.
Where the results go
The results fill downward from the cell that holds the formula. Two rules follow from that.
- The cells below must be empty. If D4 already contains a value, Sheets cannot spill into it. D2 then shows
#REF!, and the error message says the array result was not expanded because it would overwrite data in D4. Clear the blocking cell and the formula recovers. - You edit the formula in one place. Clicking a spilled cell such as D3 shows an empty formula bar. The formula lives in D2 only.
Do not leave the old per-row formulas in D3 and below when you switch to an array formula. They cause the #REF! error above. Delete them first, then enter the array formula in D2.
Adding a header from the formula
You can make the same cell produce its own header, which keeps the column's logic in one place. Put the formula in D1 and use curly braces to stack a header on top of the results:
={"Result"; ARRAYFORMULA(IF(A2:A="", "", IF(B2:B>=50, "Pass", "Fail")))}The semicolon stacks values vertically. A comma would place them side by side. The first item is the header text, and the second is the array of results. The curly-brace form is a way of building an array, so the formula does not need an outer ARRAYFORMULA. The inner one is still needed so the IF runs on the whole range.
AND and OR do not work row by row
This is the most common problem when you move from copied formulas to an array formula. This looks reasonable but is wrong:
=ARRAYFORMULA(IF(AND(B2:B>=50, C2:C>=50), "Pass", "Fail"))AND and OR collapse their inputs into a single TRUE or FALSE. Given two columns, AND asks whether every cell in both ranges passes. You get one answer, and that answer is applied to the whole column. One failing row makes every row "Fail".
The fix is to combine the comparisons with arithmetic. A comparison returns TRUE or FALSE, and arithmetic treats TRUE as 1 and FALSE as 0. A row-by-row AND is therefore a multiplication, and a row-by-row OR is an addition:
=ARRAYFORMULA(IF(A2:A="", "", IF((B2:B>=50)*(C2:C>=50), "Pass", "Fail")))Here is how the product behaves for one row:
| B>=50 | C>=50 | Product | Treated by IF as |
|---|---|---|---|
| TRUE | TRUE | 1 | TRUE |
| TRUE | FALSE | 0 | FALSE |
| FALSE | TRUE | 0 | FALSE |
| FALSE | FALSE | 0 | FALSE |
For OR, use a sum. The result is 0 only when both are FALSE, and IF treats any nonzero number as TRUE:
=ARRAYFORMULA(IF(A2:A="", "", IF((B2:B>=50)+(C2:C>=50), "Pass", "Fail")))Keep the parentheses around each comparison. Without them, operator precedence changes the meaning. For NOT, use the "not equal" operator, for example B2:B<>"Paid", instead of wrapping a range in NOT.
Functions that do work row by row
Several functions you already know behave correctly over ranges inside ARRAYFORMULA.
IFS evaluates each row independently:
=ARRAYFORMULA(IFS(A2:A="", "", B2:B>=90, "A", B2:B>=80, "B", B2:B>=70, "C", TRUE, "F"))The blank test comes first. For an empty row, its condition is TRUE, so IFS returns an empty string and never reaches the grade tests. Without that first pair, every empty row would land on the final TRUE, "F" fallback and show "F".
Nested IF works the same way. Wrap the outer IF in ARRAYFORMULA and the nested ones inherit it. You do not need ARRAYFORMULA around each IF.
IFERROR can wrap the array formula to replace errors with a message:
=ARRAYFORMULA(IFERROR(IF(A2:A="", "", IF(B2:B/C2:C>0.5, "High", "Low")), "Check data"))Each row is checked on its own. A row where C is 0 shows "Check data", and the other rows are unaffected. Because the empty-row test comes first, blank rows never reach the division.
Text comparisons over a range
Comparisons against text also work across the range, and they are still not case-sensitive:
=ARRAYFORMULA(IF(A2:A="", "", IF(A2:A="Paid", "Done", "Follow up")))This version tests A twice. Once is enough if you restructure it with IFS, but the nested form is easier to read when you are learning.
Choosing between copied formulas and ARRAYFORMULA
Neither approach is always better. Use this table to decide.
| Situation | Better choice |
|---|---|
| Data keeps growing, such as form responses | ARRAYFORMULA |
| You want one place to change the logic | ARRAYFORMULA |
| Some rows need a manual override | Copied formulas |
| Other data sits directly below the formula cell | Copied formulas, or a bounded range |
| The sheet has many thousands of rows and feels slow | Bounded range, such as `A2:A1000` |
| Collaborators are likely to type over results | ARRAYFORMULA |
A bounded range such as A2:A500 is a reasonable middle path. It limits how many rows Sheets evaluates, at the cost of stopping at row 500.
Troubleshooting checklist
When an array formula misbehaves, work through these checks:
#REF!with a message about overwriting data. A cell below the formula is not empty. Clear it.- Every row shows the same result. You probably used
ANDorORover ranges. Replace them with*and+. - Empty rows show "Fail" or "F". The blank check is missing or is not the first test.
- Only one result appears.
ARRAYFORMULAis missing, or the formula was entered without it. - Size mismatch error. The ranges have different heights. Make them all open-ended or all the same fixed length.
- A result looks right but is text. Spilled results from IF are text or numbers just like normal results. Check whether your tests compare numbers stored as text, which the earlier chapter on common mistakes covers.
Exercise
Column A holds names, B holds Score 1, and C holds Score 2, starting in row 2. Write one formula for D2 that returns "Pass" when at least one of the two scores is 50 or higher, returns "Fail" otherwise, and leaves D blank for rows with no name. It must also fill automatically as new rows are added.
Show answer
=ARRAYFORMULA(IF(A2:A="", "", IF((B2:B>=50)+(C2:C>=50), "Pass", "Fail"))) The blank check comes first so empty rows return "". The two comparisons are added because OR cannot work row by row over ranges. Addition gives 0 only when both scores are below 50, and IF treats any nonzero number as TRUE.
Exercise
A teammate wrote =ARRAYFORMULA(IF(AND(B2:B>=50, C2:C>=50), "Pass", "Fail")) in D2. Row 4 has a score of 40 in column B, and every other row has scores above 50. What does the column show, and why? How do you fix it?
Show answer
Every row shows "Fail". AND collapses both ranges into one TRUE or FALSE, and the single failing cell in row 4 makes that value FALSE for the whole column. Replace AND with multiplication: =ARRAYFORMULA(IF((B2:B>=50)*(C2:C>=50), "Pass", "Fail")). Add an A2:A="" test first if the sheet has empty rows below the data.