Sub topic 1
Cells and ranges: what you pass to a function
Prerequisites
Assume you can enter data and formulas in Google Sheets and recognize cell addresses such as B2. You should also know that columns use letters and rows use numbers.
A function receives one or more inputs, called arguments. A cell reference points to one cell. A range reference points to a rectangular group of cells. Aggregate functions such as SUM, AVERAGE, and COUNT usually receive ranges as arguments.
Cell references and ranges
A cell address combines a column letter with a row number:
B2This reference means the cell in column B and row 2. A colon creates a range:
B2:B6This is a vertical range containing B2, B3, B4, B5, and B6. A horizontal range uses the same notation:
B2:F2A rectangular range includes every cell between its top-left and bottom-right addresses:
B2:F6That range contains five columns and five rows, or 25 cells.
| Reference | Cells included | Typical use |
|---|---|---|
| `B2` | 1 | One value |
| `B2:B6` | 5 | One column of values |
| `B2:F2` | 5 | One row of values |
| `B2:F6` | 25 | A rectangular data block |
When you select a range while entering a formula, Google Sheets inserts its reference for you. You can also type the reference directly.
=SUM(B2:B6)
=AVERAGE(B2:F6)
=COUNT(C2:C100)The function decides how to use the cells in the range. The range itself only identifies which cells are available as input.
Relative and absolute references
A reference is relative when it changes as you copy a formula. For example, if =SUM(B2:B6) is in cell C2 and you copy it one column right, Sheets changes it to =SUM(C2:C6).
An absolute reference stays fixed when copied. Add dollar signs to lock the column, row, or both:
=B2*$H$1Here, B2 can change when copied, but $H$1 always refers to H1. Aggregate formulas often use relative ranges when each column has its own data. Absolute references are useful when every formula must use the same fixed range.
Passing more than one input
A function can receive several arguments separated by commas. Each argument can be a range, a cell, or a literal number.
=SUM(B2:B6, D2:D6, 100)This adds both ranges and the number 100. The ranges do not need to be adjacent. Use this form when you want to combine selected areas without including the cells between them.
flowchart TD
A["Function call"] --> B["Argument 1: B2:B6"]
A --> C["Argument 2: D2:D6"]
A --> D["Argument 3: 100"]
B --> E["SUM combines all supplied inputs"]
C --> E
D --> Ecaption: How a function receives ranges and individual values alt: A function call sends two ranges and one number to SUM, which combines all supplied inputs.
Choosing the range
A range should cover the intended data and avoid labels or result cells. For example, if values occupy B2:B6, place the total outside that range:
=SUM(B2:B6)Using the entire column can include future rows, but it can also include headers or the formula's own cell:
=SUM(B:B)If this formula is placed in column B, it includes itself and creates a circular reference. A bounded range is safer when the layout is fixed.
Exercise
What cells does =SUM(B2:D4) pass to SUM, and how many cells are included?
Show answer
It passes the rectangular range from B2 through D4. It includes 3 columns by 3 rows, for 9 cells.