Sub topic 4
Calculating with cell references instead of typed numbers
This chapter assumes you can select a cell, type a value and press Enter, and start a formula with =. It also assumes you know the operators +, -, * and /. Here you will make formulas read their inputs from other cells, so the results update when the data changes.
Why references beat typed numbers
Suppose a unit price of 4.50 is in B2 and a quantity of 12 is in C2. You could type this in D2:
=4.5*12It returns 54, but the numbers are frozen inside the formula. If the quantity changes to 15, D2 still says 54 until you edit the formula by hand.
A cell reference is the address of another cell, such as B2. When a formula contains a reference, Excel uses whatever value that cell holds at the moment of calculation. Write this in D2 instead:
=B2*C2Now D2 returns 54, and it recalculates when either B2 or C2 changes. The formula describes a relationship, not one answer.
A worked example
Enter this small order sheet:
| Row | A | B | C | D |
|---|---|---|---|---|
| 1 | Item | Unit price | Quantity | Line total |
| 2 | Notebook | 4.50 | 12 | |
| 3 | Pen | 1.20 | 40 |
Select D2, type =B2*C2 and press Enter. D2 shows 54. Select D2 again and look at the formula bar, the strip above the grid. The bar shows the formula, while the cell shows the result.
Change C2 to 15 and press Enter. D2 changes to 67.5 without you touching it.
Entering references by pointing
You can type B2, but pointing is faster and avoids typos:
- Select D2 and type
=. - Click B2. Excel inserts
B2and outlines the cell. - Type
*. - Click C2.
- Press Enter.
Excel colors each reference in the formula and outlines the matching cell in the same color. This makes it easy to see which cells feed the result.
Reference letters are not case sensitive, so =b2*c2 works. Excel converts the letters to uppercase when you press Enter.
Mixing references, numbers and operators
A formula can combine references, typed numbers and any arithmetic operator. Typed numbers are fine for values that never change, such as the 12 months in a year or the 100 in a percentage conversion.
=B2+B3adds two cells.=B2-B3subtracts one cell from another.=B2/12divides a yearly figure by the constant 12.=B2*C2+5multiplies two cells, then adds a fixed 5.
Avoid typing a value that might change. A tax rate or discount belongs in its own cell, and the formula should refer to that cell. Then you change the rate in one place and every formula follows.
Ranges are not needed yet
You may see references such as B2:B3, which mean a block of cells. Those work with functions such as SUM, which a later chapter covers. In this chapter, each reference points to one cell and you join the cells with operators.
What happens when a referenced cell is wrong
Because the formula reads other cells, problems in those cells show up in the result.
| Referenced cell holds | Formula | Result |
|---|---|---|
| A number | `=B2*C2` | A number |
| Empty | `=B2*C2` | Treated as 0, so the result is 0 |
| Text such as "twelve" | `=B2*C2` | `#VALUE!` |
| 0 or empty, as the divisor | `=A2/B2` | `#DIV/0!` |
An empty cell counts as zero in arithmetic. That can hide a missing entry, because you get 0 instead of an error. If a total looks too small, check whether a referenced cell was left blank.
Text that looks like a number is a common cause of #VALUE!. A cell holding 12 units is text, so it cannot be multiplied. Keep numbers in the cell and put units in the column heading.
For division, =A2/B2 returns #DIV/0! when B2 is 0 or empty, because division by zero is undefined. The fix is in the data, not in the formula: enter a valid divisor in B2.
Editing and checking references
To see what a formula refers to, double-click the cell or press F2. Excel outlines every referenced cell with a colored border. Press Esc to leave without changing anything.
If you move a referenced value, say by typing a new quantity in C2, you do not need to touch D2. If you type over D2 itself with a plain number, you replace the formula with a fixed value, and it stops updating. Check the formula bar when a result does not respond to changes.
Exercises
Exercise
B2 holds 80 and C2 holds 5. D2 contains =B2/C2. You change C2 to 8. What does D2 show, and do you need to edit D2?
Show answer
D2 shows 10. You do not edit D2, because it recalculates automatically from the current values in B2 and C2.
Exercise
A sheet has hours worked in B2 and an hourly rate in C2. Write a formula for D2 that returns the pay, and explain why it is better than =8*15.5.
Show answer
=B2*C2. It reads the hours and rate from cells, so it updates whenever either one changes. The formula =8*15.5 has the values fixed inside it and would need manual editing.
Exercise
D2 contains =B2*C2 and shows #VALUE!. B2 holds 4.50. What is the most likely cause, and where do you look?
Show answer
C2 probably holds text, such as "12 units", instead of a number. Check C2 and replace the entry with just the number.