Sub topic 9
Naming Ranges to Make Formulas Readable
This chapter assumes you can write formulas that start with =, use A1 references, and tell relative references from absolute ones ($F$1). You should also know what a range such as B2:B10 is. If those are new, review the earlier chapters first.
Why name a range
A formula such as =B2*$F$1 works, but a reader has to look at F1 to learn that it holds a tax rate. A named range gives a cell or range a label you choose. After you name F1 TaxRate, the formula becomes:
=B2*TaxRateNames help in four ways:
- Readability.
=Price*TaxRateexplains itself.=B2*$F$1does not. - Fewer reference mistakes. You do not have to remember which cell holds the rate or type the
$signs. - One place to update. If you move the rate to another cell, you redefine the name once. Every formula that uses it follows.
- Behavior like an absolute reference. A name always points at the same cells, wherever you copy the formula.
Creating a named range
You can define a name from the menu:
- Select the cell or range, for example F1 or B2:B10.
- Choose Data > Named ranges. The Named ranges panel opens on the right.
- Click Add a range, then type the name.
- Check the range shown under the name. Edit it if needed, then click Done.
You can also type a name in the Name box. This is the small box at the top left that normally shows the selected cell address, such as A1. Select the cells, click the Name box, type the name, and press Enter. Google Sheets creates the named range.
Rules for names
A name must follow these rules, or Sheets rejects it:
- It can contain letters, numbers, and underscores.
- It must start with a letter or an underscore, not a number.
- It cannot contain spaces or punctuation other than underscores.
- It cannot look like a cell reference or range, such as
A1orR1C1. - It cannot be
TRUEorFALSE. - It can be at most 250 characters.
- It must be unique within the spreadsheet. Names are not case-sensitive, so
taxrateandTaxRatecount as the same name.
Common styles are TaxRate, tax_rate, and Sales_Q1. Pick one style and keep to it.
Using a name in a formula
Type the name wherever a reference would go. Suppose column B holds quantities, column C holds unit prices, and F1 is named TaxRate. In D2:
=B2*C2*(1+TaxRate)While you type, Sheets suggests matching names in the autocomplete list. Pressing Tab accepts the suggestion, which also protects you from typos.
A name can refer to a whole range. If B2:B10 is named Amounts:
=SUM(Amounts)This is the same as =SUM(B2:B10). Other functions accept names in the same way, for example =AVERAGE(Amounts) and =MAX(Amounts).
A worked example
Here is a small sales sheet. Column A holds products, column B holds quantities, column C holds prices, and F1 holds a 20% tax rate.
| Cell | Content |
|---|---|
| A1:C1 | Product, Qty, Price (headers) |
| A2:C4 | Three rows of data |
| E1 | Tax rate (label) |
| F1 | 0.2 |
Name F1 TaxRate, B2:B4 Qty, and C2:C4 Price. Then use these formulas:
=SUMPRODUCT(Qty, Price)
=SUMPRODUCT(Qty, Price)*(1+TaxRate)The first formula returns the pre-tax total. The second adds tax. Each formula can be read aloud as a sentence, which =SUMPRODUCT(B2:B4,C2:C4)*(1+$F$1) cannot.
How a name behaves when you copy
A named range is absolute by default. Copying =B2*TaxRate from D2 to D3 gives =B3*TaxRate. The B2 part shifts because it is relative. The TaxRate part stays fixed.
This also means a name that covers a column range does not shift. In D3, =SUM(Amounts) still sums B2:B10, not B3:B11. If you need a formula that depends on its row, use a normal relative reference for that part.
Editing, finding, and deleting names
Open Data > Named ranges to manage names. For each entry you can:
- Rename it. Formulas that use the name update to the new name.
- Change the range it points to. Formulas keep using the name and now read the new cells.
- Delete it.
Deleting a name has a consequence that is easy to miss. Formulas that used the name do not turn back into cell references. They show #NAME?, because Sheets no longer knows what the name means. Check where a name is used before you delete it.
When you insert or delete rows and columns inside a named range, the range grows or shrinks to match. If you insert a row in the middle of B2:B10, the name now covers B2:B11. If you insert a row just below the last row, the name does not grow, so new data falls outside it.
Names and growing data
Because a name covers a fixed block, new rows added below it are not counted. You have two options.
The first is to define the name with an open-ended range. In the range box of the panel, enter Sheet1!B2:B. The name then covers every row of column B from row 2 down:
=SUM(Amounts)This works with the name Amounts defined as Sheet1!B2:B. New rows are counted without any change.
The second is to leave the name on a fixed block and redefine it as the data grows. This is more work and easy to forget, so the open-ended form is usually better. Be aware that the open-ended form includes any stray values below your data, such as a notes cell or a total row. A total placed in the same column would be counted inside its own sum and could cause a circular dependency error.
Names across sheets
A name is global to the spreadsheet. A formula on any sheet can use it without a sheet prefix. If TaxRate points at Settings!B1, then this works on the sheet Orders:
=B2*TaxRateCompare it with the plain reference version, =B2*Settings!$B$1. This is the main practical use of names: configuration values on one sheet, used from many others.
Names refer to ranges in the same spreadsheet. They do not reach into other spreadsheets. To use data from another file, bring it in with IMPORTRANGE and name the cells that hold the imported result if you want to refer to them by name.
If you rename the sheet a name points to, Sheets updates the name's range for you.
Diagram: how a name resolves
The diagram shows what happens when a cell contains =B2*TaxRate.
Common problems
| Symptom | Likely cause | Fix |
|---|---|---|
| `#NAME?` after typing a name | Typo, or the name does not exist | Check the spelling against **Data > Named ranges** |
| `#NAME?` in formulas that worked before | The name was deleted | Recreate the name with the same spelling |
| Sheets will not accept a name | It breaks a naming rule, such as a space or a cell-like name such as `Q1` | Use `Sales_Q1` or `Q1_Sales` instead |
| New rows are missing from a total | The name covers a fixed block | Redefine the name as an open-ended range |
| A name returns a wrong value after a restructure | The name still points at the old cells | Open the panel and correct the range |
A name that looks like a cell address is a frequent surprise. Q1, AB12, and Tax2 are all valid cell addresses in Sheets, so you cannot use them. Add an underscore or a word, such as Tax_2.
When not to use a name
Names are not always better. For a one-off formula on adjacent cells, such as =B2*C2, a name adds a lookup step for no benefit. Too many names also make a spreadsheet harder to audit, because a reader must open the panel to see where each one points. A good rule is to name things that are reused in many formulas, such as rates, thresholds, and key data columns, and to leave ordinary row-by-row references alone.
Summary
- A named range labels a cell or range so formulas read as words.
- Create names with Data > Named ranges or the Name box.
- Names must start with a letter or underscore, contain no spaces, and not look like a cell address.
- A name behaves like an absolute reference when copied.
- Deleting a name leaves
#NAME?in the formulas that used it. - Define a name over an open-ended range such as
Sheet1!B2:Bso it covers new rows.
Exercise
A sheet has a tax rate in Settings!B1, named TaxRate. On the sheet Orders, you enter =B2*TaxRate in D2 and fill it down to D3 and D4. Later, someone deletes the name TaxRate. What do D2, D3, and D4 show, and how do you repair them?
Show answer
All three cells show #NAME?. Deleting a name does not convert the formulas back into cell references, so Sheets no longer recognizes TaxRate. To repair them, open Data > Named ranges, create the name TaxRate again with the same spelling, and point it at Settings!B1. The formulas then work again without being edited.
Exercise
The name Amounts is defined as Sheet1!B2:B10. You add new data in B11 and B12, and =SUM(Amounts) does not change. How do you fix it so future rows are counted too, and what risk does your fix carry?
Show answer
Redefine Amounts as the open-ended range Sheet1!B2:B in Data > Named ranges. Then =SUM(Amounts) covers every row of column B from row 2 down. The risk is that any other value in column B below the data, such as a note or a total, is also included in the sum.