Sub topic 8
Worked example: a multiplication table from one formula
This chapter builds a complete multiplication table from a single formula. You will type the formula once, copy it across a block of cells, and see why each cell gets the right answer. The technique is the mixed reference, a reference that locks only the row or only the column.
Prerequisites assumed: you can enter values and formulas in Google Sheets, you know addresses such as A1 and B2, and you have read the earlier chapters on relative and absolute references. You should know that $A$1 is fully locked and that A1 shifts in both directions when copied.
What you are building
A two-way table has one set of labels down the left side and another set across the top. Each cell inside the table combines the label at the start of its row with the label at the top of its column. A multiplication table is the simplest example. The cell in row 3 and column 4 holds 3 × 4.
The goal is a table like this, where the grey labels are typed by hand and the inner cells are all produced by one formula:
| Row | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| **1** | 1 | 2 | 3 | 4 |
| **2** | 2 | 4 | 6 | 8 |
| **3** | 3 | 6 | 9 | 12 |
| **4** | 4 | 8 | 12 | 16 |
You could type 16 formulas by hand, but that is slow and easy to get wrong. A single formula with the right locks does the job.
Step 1: lay out the labels
Leave A1 empty. Enter the column headers in B1:E1 and the row headers in A2:A5.
| Cell | Value |
|---|---|
| B1 | 1 |
| C1 | 2 |
| D1 | 3 |
| E1 | 4 |
| A2 | 1 |
| A3 | 2 |
| A4 | 3 |
| A5 | 4 |
You can type these by hand. You can also type 1 and 2 in the first two cells and drag the fill handle, and Sheets will continue the series.
Step 2: think about what each cell needs
Before typing the formula, decide which cells each result must read. Take three cells from the table:
- B2 needs the row label in A2 and the column label in B1.
- C2 is in the same row as B2, so it needs A2 again and the column label C1.
- B3 is in the same column as B2, so it needs B1 again and the row label A3.
The pattern is:
- When you copy across, the row label must stay in column A, and the column label must move one column to the right.
- When you copy down, the column label must stay in row 1, and the row label must move one row down.
So the row label needs its column locked but its row free. The column label needs its row locked but its column free. That is exactly what mixed references do.
Step 3: write the formula
In B2, enter:
=$A2*B$1Read it one reference at a time.
| Reference | Type | Locked part | Free part | Effect when copied |
|---|---|---|---|---|
| `$A2` | Mixed (column locked) | Column A | Row number | Always reads column A. The row follows the formula down. |
| `B$1` | Mixed (row locked) | Row 1 | Column letter | Always reads row 1. The column follows the formula across. |
The $ sign always sits directly in front of the part it locks. In $A2 it is in front of the letter, so the column is locked. In B$1 it is in front of the number, so the row is locked.
Step 4: copy the formula
Select B2 and copy it to the whole block B2:E5. You have three ways to do it.
- Drag the fill handle (the small square at the bottom-right corner of the selected cell) to the right across C2:E2. Then select B2:E2 and drag its fill handle down to row 5.
- Select B2, press Ctrl+C (Cmd+C on Mac), select B2:E5, and press Ctrl+V (Cmd+V on Mac).
- Select B2:E5 directly, so that B2 is the top-left cell, and press Ctrl+Enter after typing the formula into B2. Alternatively, fill with Ctrl+R for right and Ctrl+D for down.
Double-click autofill is less useful here. It fills downward only, and it stops where the neighboring column ends. Use it for a single column, not for a two-dimensional block.
Step 5: check how the formula changed
Click a few cells and read the formula bar. Sheets rewrote each copy according to its position.
| Cell | Formula after copying | Calculation | Result |
|---|---|---|---|
| B2 | `=$A2*B$1` | 1 × 1 | 1 |
| C2 | `=$A2*C$1` | 1 × 2 | 2 |
| E2 | `=$A2*E$1` | 1 × 4 | 4 |
| B3 | `=$A3*B$1` | 2 × 1 | 2 |
| C3 | `=$A3*C$1` | 2 × 2 | 4 |
| E5 | `=$A5*E$1` | 4 × 4 | 16 |
In every copy, $A stayed on column A and $1 stayed on row 1. Only the free parts moved.
Why the other lock patterns fail
It helps to see the wrong versions. Each one looks plausible and gives a visibly broken table.
| Formula in B2 | What goes wrong |
|---|---|
| `=A2*B1` | Nothing is locked. In C2 the formula becomes `=B2*C1`. It multiplies the previous result by an empty or wrong cell. |
| `=$A$2*$B$1` | Everything is locked. Every cell shows 1, because every copy still reads A2 and B1. |
| `=A$2*$B1` | The locks are swapped. The row label stays on row 2 and the column label stays on column B, so the table has repeated values and the wrong pattern. |
| `=$A2*B1` | The column label is not row-locked. Copying down moves it to B2, B3 and so on, which reads the table's own cells. |
The last case is the most subtle. The first row can look correct, because row 1 is still the reference there. The error appears only after you copy down. Always check a cell in the last row and the last column, not just the first one.
Typing the dollar signs quickly
You do not have to type each $ by hand. Click inside the reference in the formula bar, or place the cursor next to it, and press F4 (Windows) or Cmd+T on some Mac setups. Each press cycles the reference through four states:
A2(both relative)$A$2(both locked)A$2(row locked)$A2(column locked)
For $A2, press F4 three times from the plain A2. For B$1, press it twice from B1. Keyboard shortcuts for this vary by platform and browser, so if F4 does nothing, type the $ characters directly. Typing always works.
Variations of the same pattern
Once you understand the structure, you can swap the operation or the labels without changing the locks.
Changing the operation
The locks depend on where the labels are, not on what you do with them. For an addition table, use:
=$A2+B$1For a table of powers, with the base in column A and the exponent in row 1:
=$A2^B$1Changing the size
The table does not have to be 4 × 4. If you type labels 1 to 12 across the top and down the side and copy the formula over the larger block, you get a full 12 × 12 table. The formula in B2 stays the same.
Using real data
The same layout works for any two-factor calculation. Suppose A2:A4 hold product prices and B1:D1 hold discount percentages (0.1, 0.2, 0.3). The discounted price for each combination is:
=$A2*(1-B$1)The structure is identical. Only the arithmetic inside differs. Format B1:D1 as percentages if you prefer to see 10%, 20% and 30%. The underlying values remain 0.1, 0.2 and 0.3.
An alternative: one formula for the whole table
Google Sheets can also produce the entire table from one formula in B2 with no copying. ARRAYFORMULA runs a calculation over whole ranges at once. For the multiplication table:
=ARRAYFORMULA(A2:A5*B1:E1)A column range multiplied by a row range expands into a grid, so this formula fills B2:E5 on its own. The results spill into the neighboring cells. You must leave those cells empty, or Sheets shows a #REF! error saying the array result was not expanded.
| Approach | Strengths | Limits |
|---|---|---|
| Mixed references and copying | Works in every spreadsheet program. Each cell can be edited alone. | You must copy the formula and keep the locks correct. |
| `ARRAYFORMULA` | One formula to maintain. Resizes only when you change the range. | Individual cells in the result cannot be edited. The block must stay empty. |
Mixed references are still worth learning. Many sheets you will meet use them, and they apply to cases where an array formula is awkward to write.
Troubleshooting checklist
If your table is wrong, work through these checks in order.
- Click B2 and confirm the formula is exactly
=$A2*B$1. Check that each$sits in front of the right character. - Click the bottom-right cell, E5. It should read
=$A5*E$1. If it does not, the copy did not cover the whole block. - Check the labels. A label stored as text, such as
'1, may left-align and cause#VALUE!errors when multiplied. - Look for stray values in A1. A1 is not used by the formula, but a value there can confuse you when you read the layout.
- Check that no cell in B2:E5 holds a typed number instead of a formula. Hard-coded numbers stay the same when you change a label.
Exercise
You enter =$A2*B$1 in B2 and copy it to cell D4. What formula appears in D4, and what does it show if A4 holds 3 and D1 holds 5?
Show answer
D4 holds =$A4*D$1. The column A and row 1 locks stay in place, and the free parts move two rows down and two columns right. With A4 = 3 and D1 = 5, the result is 15.
Exercise
You need a table of discounted prices. Prices are in A2:A10 and discount rates are in B1:F1. Write the formula for B2 so that it can be copied across B2:F10, and name the two reference types you used.
Show answer
=$A2*(1-B$1). The reference $A2 is a mixed reference with the column locked, so it always reads the price in column A. The reference B$1 is a mixed reference with the row locked, so it always reads the discount rate in row 1.
Exercise
A learner filled the table from =$A$2*B$1 and every row shows the same values as row 2. What is the mistake, and how is it fixed?
Show answer
The row label reference is fully locked ($A$2), so every copy reads A2. Remove the dollar sign in front of the row number to get $A2, then copy the formula again.