Sub topic 10
Using whole-column references
This chapter assumes you can write SUM, AVERAGE, COUNT, MIN, and MAX over a normal range such as B2:B6. It also assumes you know how text, blanks, and zeros are treated. Here you will learn what changes when the range is a whole column such as B:B. You will also learn when that is convenient and when it causes errors.
What a whole-column reference is
A whole-column reference names every cell in one column. The notation is the column letter, a colon, and the same letter again.
=SUM(B:B)This formula covers B1, B2, and every row below, up to the last row of the sheet. A new Google Sheets file has 1000 rows by default, so the range is 1000 cells tall until you add more.
Two related forms are worth knowing:
| Reference | Meaning | Grows with new rows? |
|---|---|---|
| `B2:B6` | Fixed range, five cells | Only if rows are inserted inside it |
| `B:B` | Entire column B, including the header row | Yes |
| `B2:B` | Column B from row 2 down, which skips the header | Yes |
| `B:D` | Entire columns B, C, and D | Yes |
The open-ended form B2:B is specific to Google Sheets. It lets you start at a chosen row and run to the bottom. Many people prefer it to B:B because it excludes the header on purpose.
Why use it: data that keeps growing
Suppose column B holds daily sales and you add a row each day. With =SUM(B2:B6), a new value in B7 is not included. You would have to edit the formula every time.
With a whole-column reference, the formula never needs editing:
=SUM(B:B)
=AVERAGE(B:B)
=MAX(B:B)The new row is counted as soon as you type the value.
The same applies to inserted and deleted rows. If you delete row 4, the reference stays B:B. A fixed range such as B2:B6 would shrink to B2:B5.
Walkthrough: a growing sales list
Consider this sheet. Row 1 is a header row.
| Row | A | B |
|---|---|---|
| 1 | Item | Amount |
| 2 | Apples | 120 |
| 3 | Pears | 80 |
| 4 | Apples | 100 |
| 5 | Plums | 60 |
Put the following formulas in column D, not in column B:
=SUM(B:B)
=COUNT(B:B)
=AVERAGE(B:B)
=MIN(B:B)
=MAX(B:B)The results are 360, 4, 90, 60, and 120.
Notice that the header text "Amount" in B1 does not disturb anything. SUM, AVERAGE, COUNT, MIN, and MAX all skip text in a range. The empty cells below row 5 are skipped too. This is why whole-column references are safe with these five functions: blanks and text are ignored, so the extra cells add nothing.
Now type 40 into B6. The total becomes 400, the count becomes 5, and the average becomes 80. You edited no formula.
Where whole-column references go wrong
Circular references
The most common mistake is putting the formula inside the column it reads. This happens when you type a total at the bottom of the data:
=SUM(B:B)If you enter this in B20, the formula includes its own cell. Sheets shows #REF! with the message "Circular dependency detected". The cell cannot compute itself.
The fixes are:
- Put the total in a different column, such as
D1. - Put the total above the data in a spare row.
- Use a fixed range that stops before the total, such as
B2:B19.
The third fix gives up the automatic growth. The first two keep it.
Numbers in the header or in stray cells
A whole-column range includes the header row. Text headers are ignored, but a numeric header is not. A column titled 2024 is a number, and SUM(B:B) will add 2024 to your total. COUNT(B:B) will count it too.
Stray values cause the same problem. A note such as a typed 5 in B500, or a subtotal you pasted far down the column, is included without any warning. When a total looks too high, scan the entire column. Choose Edit, then Find and replace, then search within the sheet. Or press Ctrl+Down Arrow in the column to jump to the last filled cell.
If the header could be numeric, use B2:B instead of B:B.
Counting blanks
COUNTBLANK behaves differently from the other functions because it counts the empty cells, and a whole column has many of them. With data in B1:B5 on a fresh 1000-row sheet:
=COUNTBLANK(B:B)returns 995, not 0. The answer depends on how many rows the sheet has, so it changes whenever someone adds rows. Use a bounded range for blank counts, for example B2:B101 when you expect 100 entries.
COUNTA has a similar catch. =COUNTA(A:A) counts the header "Item" as well, so it returns one more than the number of data rows. Subtract 1, or use A2:A.
=COUNTA(A2:A)Empty columns
When the column holds no numbers at all, the functions behave as they do with any empty range:
| Formula | Result on an empty column |
|---|---|
| `=SUM(B:B)` | 0 |
| `=COUNT(B:B)` | 0 |
| `=MIN(B:B)` | 0 |
| `=MAX(B:B)` | 0 |
| `=AVERAGE(B:B)` | `#DIV/0!` |
A MIN of 0 can be misleading, because it looks like a real data value. If a new sheet shows a minimum of 0 and you do not expect it, check whether the column is empty. For the #DIV/0! error, wrap the formula as you did earlier:
=IFERROR(AVERAGE(B:B), "No data")Performance
Sheets handles a whole-column reference to a plain column with no trouble. The cost grows when you combine many whole-column formulas with heavy functions or with ARRAYFORMULA. Each formula then scans all the rows. In a large workbook with hundreds of such formulas, recalculation can slow down. If that happens, switch to a bounded or open-ended range such as B2:B5000.
Multiple columns and mixed arguments
You can pass more than one whole column, or mix them with other arguments, in the same way as ordinary ranges:
=SUM(B:B, D:D)
=SUM(B:D)The first adds columns B and D and skips C. The second adds B, C, and D. Be careful with the second when column C holds something you do not want added, such as an ID number. The function adds every number it finds.
Choosing the right reference
The diagram shows how to pick a form.
Summary of behaviors
- A whole-column reference such as
B:Bcovers every row, so new data is included automatically. SUM,AVERAGE,COUNT,MIN, andMAXskip text and blanks, so the header and the empty rows do not change the result.- A numeric header or a stray number is counted. Use
B2:Bto avoid the header. COUNTBLANKon a whole column counts every empty cell down to the last row of the sheet. Use a bounded range.- On an empty column,
AVERAGEgives#DIV/0!andMINandMAXgive 0. - A formula placed inside its own column creates a circular dependency.
Exercise
Column A holds names with the header "Name" in A1 and 12 names below. You enter =COUNTA(A:A) in cell D1 and get 13. What formula gives the number of names, and why is the original answer one too high?
Show answer
=COUNTA(A2:A) returns 12. The whole-column reference A:A includes A1, and COUNTA counts every non-empty cell including text, so the header "Name" is counted. Starting at row 2 excludes it. Subtracting 1 from the original formula also works, but it breaks if the header is removed.
Exercise
Your sales data is in B2:B50. You type =SUM(B:B) into B51 to show the total, and the cell shows #REF!. Give two ways to fix it and say which one keeps the total growing with new rows.
Show answer
The cell is inside the range it sums, which is a circular dependency. Fix 1: move the formula to another column or above the data, for example =SUM(B:B) in D1. This keeps the automatic growth. Fix 2: change the formula to =SUM(B2:B50), which stops before the total. This removes the circular reference but does not include rows added later.
Exercise
A sheet has a text header in B1 and no other data in column B. What do =SUM(B:B), =MAX(B:B), and =AVERAGE(B:B) return, and how would you make the last one show "No data"?
Show answer
=SUM(B:B) returns 0 and =MAX(B:B) returns 0, because the text header is ignored and no numbers remain. =AVERAGE(B:B) returns #DIV/0! because there are no numbers to divide by. Use =IFERROR(AVERAGE(B:B), "No data").