Sub topic 8
Your First Formulas and Cell References
This chapter assumes you can open a spreadsheet in Google Sheets, click a cell, type into it, and tell text, numbers and dates apart. You should also know that columns have letters and rows have numbers. Here you will write your first formulas, learn how cell references work, and learn to read the most common errors.
What a formula is
A formula is an instruction in a cell that tells Sheets to calculate a value. Every formula starts with an equals sign (=). Without it, Sheets treats what you type as plain text.
Once you press Enter, the cell shows the result. The formula itself stays in the cell and appears in the formula bar when you select the cell.
The key benefit is that formulas are live. If a number the formula depends on changes, the result updates by itself. You never retype the total.
Cell references
A cell reference is the address of a cell: its column letter followed by its row number. B2 means column B, row 2.
A range is a block of cells. You write it with the first and last cell separated by a colon. B2:B6 means B2, B3, B4, B5 and B6. A range can also span several columns, for example B2:C6.
Using references instead of typed numbers is what makes a spreadsheet useful. Compare these two formulas:
=12*4.50always gives the same answer, and you must edit the formula to change it.=B2*C2reads the current values in B2 and C2, so it follows any edit you make to them.
A worked example: a small order sheet
Build this sheet on Sheet1. Type the headings in row 1 and the data below them.
| Row | A | B | C | D |
|---|---|---|---|---|
| 1 | Item | Quantity | Unit price | Line total |
| 2 | Notebooks | 12 | 3.50 | |
| 3 | Pens | 40 | 0.80 | |
| 4 | Folders | 25 | 1.20 | |
| 5 | Stapler | 3 | 9.99 | |
| 6 | Tape | 10 | 2.25 |
Multiply with cell references
In D2, type:
=B2*C2Press Enter. D2 now shows 42, which is 12 multiplied by 3.50. The * symbol means multiply. The other basic operators are + for add, - for subtract, / for divide and ^ for a power.
Add up a range with SUM
A function is a built-in formula with a name. You give it inputs, called arguments, inside parentheses. SUM adds its arguments.
To total the quantities, click B7 and type:
=SUM(B2:B6)The result is 90. The range B2:B6 is the single argument.
Find the mean with AVERAGE
AVERAGE adds the numbers in its arguments and divides by how many numbers there are.
=AVERAGE(B2:B6)The result is 18. AVERAGE ignores empty cells and cells that contain text. This matters when a blank cell sits inside your range, because it is not counted as a zero.
Insert the current date with TODAY
=TODAY()TODAY takes no arguments, but the parentheses are still required. It returns the current date and recalculates whenever the spreadsheet is opened or changed. Use it for "as of" dates, not for a date you want to keep fixed. For a fixed date, type the date itself.
Typing formulas efficiently
You do not have to type every reference. Several shortcuts reduce typos.
- Type
=, then click a cell. Sheets inserts its address for you. - For a range, click the first cell and drag to the last one while the formula is open.
- Type a function name and Sheets offers a suggestion box. Press Tab to accept one.
- Press F2 or double-click a cell to edit its formula. Colored outlines on the sheet show which cells each reference points to.
The colored outlines are a good way to check your own work. If an outline surrounds the wrong cells, you have found the mistake.
Copying a formula down a column
You do not need to retype =B2*C2 for each row. Select D2, then drag the small square in its bottom-right corner (the fill handle) down to D6. Double-clicking the fill handle fills down as far as the neighboring data goes.
Sheets adjusts the references as it copies. D3 becomes =B3*C3, D4 becomes =B4*C4, and so on. This behavior is called a relative reference, and it is the default.
Relative and absolute references
A relative reference describes a position relative to the formula's own cell. "Two columns to the left, same row" stays true wherever you copy the formula.
Sometimes you want a reference that never moves. An absolute reference does this. You add a dollar sign ($) before the column letter, the row number, or both.
| Form | Example | Column when copied | Row when copied |
|---|---|---|---|
| Relative | `B2` | changes | changes |
| Absolute | `$B$2` | fixed | fixed |
| Mixed, row fixed | `B$2` | changes | fixed |
| Mixed, column fixed | `$B2` | fixed | changes |
A common use is a single value that many formulas share, such as a tax rate. Suppose F1 holds the rate 0.08 and you want a tax amount in column E:
=D2*$F$1When you copy this down, D2 becomes D3, D4 and so on, but $F$1 stays on the tax rate. Without the dollar signs, the reference would drift to F2, F3 and so on, and the results would be wrong.
To add dollar signs quickly, click inside a reference in the formula bar and press F4. Each press cycles through the four forms.
References to other sheets
A formula can read a cell on another sheet tab in the same file. Write the sheet name, an exclamation mark, then the reference:
=Sheet2!B2If the sheet name contains spaces, put it in single quotes: ='Q1 Sales'!B2. Renaming a tab updates formulas that already point to it.
How Sheets evaluates a formula
Sheets follows the usual order of operations: parentheses first, then powers, then multiplication and division, then addition and subtraction. Operators at the same level run left to right.
=2+3*4gives 14.=(2+3)*4gives 20.
When in doubt, add parentheses. They cost nothing and make your intent clear to the next reader.
Common errors and what they mean
Sheets shows an error code in a cell when it cannot compute the result. Hover over the cell to see an explanation.
| Error | Typical cause | Fix |
|---|---|---|
| `#DIV/0!` | The formula divides by zero or by an empty cell. | Check the divisor cell. |
| `#NAME?` | A function name is misspelled, or text is not in quotes. | Correct the spelling. |
| `#REF!` | A referenced cell or sheet was deleted. | Rewrite the reference. |
| `#VALUE!` | The formula expected a number but found text. | Check the cells for stray text. |
| `#N/A` | A lookup found no match. | Check the value you are searching for. |
Also watch for these quiet problems that produce no error code.
- Numbers stored as text. A number with a leading apostrophe, or pasted with extra characters, is text.
SUMskips it, so your total comes out too low. Text usually aligns to the left of a cell and numbers to the right, which is a quick clue. - A missing equals sign. Typing
SUM(B2:B6)shows the words, not a total. - A range that is too short. If you add a row below the range,
SUM(B2:B6)will not include it. Inserting a row inside the range expands it automatically, but adding one after the last row does not. - Accidental self-reference. A formula in B7 that includes B7 in its range creates a circular dependency. Sheets reports an error. Move the formula outside its own range.
Formulas and data types
The previous chapter showed how Sheets decides whether an entry is text, a number or a date. That decision affects formulas. A date is stored as a number of days, so you can subtract one date from another:
=TODAY()-A2If A2 holds a date, this returns the number of days between that date and today. You may need to change the result cell's format to Number so it does not display as a date.
A practical checklist
Before you trust a sheet with formulas, go through these checks.
- Select each formula cell and read it in the formula bar.
- Confirm every range covers all of the rows you intend.
- Test with a simple case, such as numbers where you know the total.
- Change one input and confirm the result changes.
- Check any shared value, such as a tax rate, is referenced with
$.
Exercise
In a sheet, F1 holds a discount rate of 0.1, and D2:D6 hold prices. You write =D2$F$1 in E2 and fill it down to E6. What formula appears in E4, and what would it have been if you had written =D2F1 instead?
Show answer
E4 contains =D4$F$1. The absolute reference $F$1 stays fixed, and D2 shifts to D4 because it is relative. With =D2F1, E4 would contain =D4*F3, which points at an empty cell, so the result would be 0 and wrong.
Exercise
Using the order sheet from this chapter, write one formula for the total of all the line totals in D2:D6, and one formula for the average unit price in C2:C6. Then say what AVERAGE does with a blank cell inside its range.
Show answer
The total is =SUM(D2:D6). The average unit price is =AVERAGE(C2:C6). AVERAGE ignores blank cells and cells with text, so a blank is not counted as zero and does not lower the result.