Sub topic 12
Alternatives: Named Ranges and ARRAYFORMULA
What this chapter assumes
You should already know how relative, absolute, and mixed references behave when you copy a formula. You should also be comfortable with $ signs, the fill handle, and the tax-rate and multiplication-table examples from earlier chapters. This chapter does not replace those skills. It shows two ways to avoid some of the copying and locking, and it explains when each way is the better choice.
Why look for alternatives
Absolute references work, but they have costs:
- A formula such as
=A2*$E$1does not say whatE1means. A reader has to click the cell to find out. - Every formula that uses a fixed cell needs correct
$signs. One missed sign gives a wrong result without any error message. - A formula must be copied into every row. If you forget to extend it to new rows, the new rows stay empty.
Two Google Sheets features address these problems. Named ranges replace a cell address with a readable name. ARRAYFORMULA replaces many copied formulas with a single formula.
Named ranges
A named range is a label that you attach to a cell or a block of cells. A name always points to the same fixed location, so it behaves like an absolute reference with a readable name.
Creating a named range
- Select the cell or range, for example the tax rate in
E1. - Choose Data > Named ranges. The Named ranges panel opens.
- Type a name, such as
TaxRate, and confirm the range shown. - Click Done.
You can also select the cell and type the name into the box to the left of the formula bar, where the cell address normally appears.
Rules for names
Sheets accepts a name only if it follows these rules:
- It contains only letters, numbers, and underscores. Spaces are not allowed, so use
Tax_RateorTaxRate. - It does not start with a number.
- It does not look like a cell address or a range, so
A1,B2:C5, andR1C1are rejected. - It does not duplicate another named range in the same spreadsheet.
Using a name in a formula
With TaxRate defined as E1, the price list formula becomes:
Named range TaxRate = E1
=A2*TaxRateYou can fill this formula down column B. The name does not shift, because it refers to one fixed cell, so no $ signs are needed. Typing the first letters of a name in a formula also shows it in the autocomplete list.
Names for whole ranges
A name can point to a block of cells. This is useful for the lookup ranges that earlier chapters locked with $:
Named range SalesRegion = A2:A100
Named range SalesAmount = B2:B100
=SUMIF(SalesRegion, D2, SalesAmount)The formula =SUMIF(SalesRegion, D2, SalesAmount) reads as plain language. It does the same job as =SUMIF($A$2:$A$100, D2, $B$2:$B$100), and it can be filled down a list of criteria in column D. The same approach works for VLOOKUP:
Named range PriceTable = G2:H50
=VLOOKUP(D2, PriceTable, 2, FALSE)Names work across sheets
A named range is available in the whole spreadsheet. A formula on any sheet can use TaxRate without the Settings! prefix that a cross-sheet absolute reference needs. If TaxRate points to Settings!B1, then =A2*TaxRate works on every sheet.
How a name behaves when the sheet changes
| Change to the sheet | Effect on the named range |
|---|---|
| Insert a row above the range | The name moves with the cells and still points to the same data. |
| Insert a row inside a multi-cell range | The range grows to include the new row. |
| Delete the cells the name points to | The name loses its target and formulas that use it return `#REF!`. |
| Delete the named range itself | Formulas that use it return `#NAME?`. |
| Rename the range in the panel | Formulas that use it update to the new name. |
The last row of the table is a useful property. To change which cell holds the tax rate, you edit the range once in the Named ranges panel. You do not edit every formula.
Limits of named ranges
- A name does not make a reference relative. If you need a reference that moves with each row, use an ordinary relative reference.
- A name always points to one fixed area. It cannot express "the cell in this row, but column E". Mixed references such as
$A2have no named-range equivalent. - A name hides its location. A reader must open the panel to see where
PriceTableactually is, so choose names that describe the content.
ARRAYFORMULA
ARRAYFORMULA lets one formula produce a whole block of results. You write it once in the top cell, and Sheets fills the cells below (or beside) it. Because nothing is copied, the question of how references shift when you copy does not arise.
The basic pattern
Suppose prices are in A2:A11 and the tax rate is in E1. Enter this in B2 only:
=ARRAYFORMULA(A2:A11*$E$1)Sheets calculates all ten results and displays them in B2:B11. Only B2 contains a formula. The cells below it show the output and cannot be edited on their own.
Two points matter here:
- The range
A2:A11is treated as a whole list. Each price is multiplied by the single value inE1. - The
$signs onE1are not required for correctness, since the formula is never copied. Keep them if you plan to copy the formula to another column, or useTaxRateinstead.
You can also enter the formula normally and press Ctrl+Shift+Enter (Cmd+Shift+Enter on a Mac). Sheets wraps the formula in ARRAYFORMULA for you.
Open-ended ranges
A range such as A2:A has no end row, so it grows as you add data. A plain version of the formula puts zeros in every empty row, because a blank cell counts as 0. Add an IF to keep the empty rows blank:
=ARRAYFORMULA(IF(A2:A="", "", A2:A*TaxRate))For each row, the formula checks whether column A is empty. If it is, it returns an empty string. Otherwise it multiplies the price by the rate. New prices typed in column A get their tax calculated automatically, with no fill step.
A two-way table from one formula
The multiplication table from an earlier chapter needed the mixed reference =$A2*B$1, copied across and down. With ARRAYFORMULA, a column of values times a row of values produces the whole grid. Put the row headers in A2:A5 and the column headers in B1:E1, then enter this in B2:
=ARRAYFORMULA(A2:A5*B1:E1)The result fills B2:E5. Each result cell multiplies the header in its row by the header in its column, which is exactly what the mixed reference did.
Criteria lists
The SUMIF example from earlier needed to be filled down column D. With ARRAYFORMULA, one formula can handle the whole list of criteria:
=ARRAYFORMULA(SUMIF(A2:A100, D2:D6, B2:B100))This returns one total for each value in D2:D6, spread down the column beside the criteria.
Errors and limits
The most common error is blocked output. If any cell in the area the results need already contains data, the formula returns #REF! with the message "Array result was not expanded because it would overwrite data in B5". Clear the blocking cell and the results appear.
Other points to watch:
- You cannot overwrite or delete part of the result block. Edit the formula in its top cell instead.
- Mixing text and numbers in a range gives
#VALUE!in the affected rows. A header cell inside the range, such asA1:A11*$E$1, is a typical cause. - Very large open-ended ranges, such as whole columns used in many array formulas, slow a spreadsheet down.
- Not every function accepts arrays in every argument. If the output is a single value instead of a list, test the function on a small range first.
Choosing between the approaches
The diagram shows one way to decide. Start with what you are trying to avoid.
The same comparison in table form:
| Approach | Strength | Weakness |
|---|---|---|
| Absolute reference (`$E$1`) | Visible in the formula, no setup | Easy to mistype, cryptic to readers |
| Named range (`TaxRate`) | Readable, changed in one place | Setup step, location is hidden |
| Mixed reference (`$A2`, `B$1`) | One formula fills a grid when copied | Needs careful `$` placement |
| ARRAYFORMULA | One formula, no copying, grows with data | Output cells are locked, can be blocked by data |
Combining the approaches
The approaches work well together. A common design keeps inputs on a Settings sheet, names them, and uses one array formula to apply them:
Named range TaxRate = Settings!B1
=ARRAYFORMULA(IF(A2:A="", "", A2:A*(1+TaxRate)))This formula gives the price including tax for every row. It reads clearly, it has no $ signs to get wrong, it needs no copying, and the tax rate lives in one place.
Exercises
Exercise
A formula in B2 is =A2*$E$1 and is filled down 500 rows. You want to make the formula easier to read. Which feature would you use, and what would the new formula look like if the name is TaxRate?
Show answer
Use a named range. Select E1, open Data > Named ranges, and name it TaxRate. The formula becomes =A2*TaxRate. It can be filled down without $ signs because the name always points to E1.
Exercise
You enter =ARRAYFORMULA(A2:A*TaxRate) in B2. Column A holds 8 prices, and rows 10 and below are empty, but B10 and below show 0. How do you fix this?
Show answer
A blank cell counts as 0 in arithmetic, so empty rows return 0. Wrap the calculation in an IF that tests for blanks: =ARRAYFORMULA(IF(A2:A="", "", A2:A*TaxRate)).
Exercise
You entered an ARRAYFORMULA in C2 that should fill C2:C20, but it shows #REF! with the message that the array result was not expanded. What is the likely cause and the fix?
Show answer
Some cell in C3:C20 already contains data, so the results would overwrite it. Clear that cell (or move the data) and the results will appear.
Exercise
Why can a named range not replace the mixed reference $A2 in the multiplication table formula =$A2*B$1?
Show answer
A named range always points to one fixed area. A mixed reference locks only the column or only the row, so it follows the current row while staying in column A. A name cannot follow the formula's position that way. In this case you would use ARRAYFORMULA(A2:A5*B1:E1) or keep the mixed reference.