Sub topic 8
Combining several ranges, values, and whole columns
This chapter assumes you can write a single-range formula such as =SUM(B2:B6). You should also know how the five functions treat blanks and text inside a range. It covers feeding one function several inputs at once. It also covers the shortcut of referencing a whole column, which is convenient but has some traps.
The sample data
The examples use this layout. Column C holds text notes, and the other columns hold numbers.
| Row | A | B | C | D |
|---|---|---|---|---|
| 1 | Region | Q1 | Note | Q2 |
| 2 | East | 120 | 90 | |
| 3 | West | 80 | ok | 110 |
| 4 | North | 100 | 70 | |
| 5 | South | 60 | late | 130 |
| 6 | Central | 140 | 120 |
The Q1 column totals 500 and the Q2 column totals 520.
Several arguments in one call
The five functions take a list of arguments separated by commas. Each argument can be a range, a single cell reference, a typed constant, or another formula. Excel allows up to 255 arguments per call.
=SUM(B2:B6, D2:D6)
=SUM(B2:B6, D2:D6, 100)
=SUM(B2, B4, B6)
=SUM(B2:B6, D2:D3, 100, MAX(D2:D6))The first formula returns 1020, and the second returns 1120. The third adds three separate cells and returns 340. The fourth mixes ranges, a constant, and a nested function.
Some language and regional settings use a semicolon as the argument separator. If a formula from this chapter is rejected, check your list separator setting.
Excel does not require the ranges to be the same size or shape, and it does not care how far apart they are. Excel gathers every numeric value from every argument into one pool and then applies the function to the pool.
Pooling changes the meaning of AVERAGE
Pooling matters most for AVERAGE. The function does not average each argument and then average those results. It divides the grand total by the count of all numbers.
=AVERAGE(B2:B6, D2:D4)
=AVERAGE(AVERAGE(B2:B6), AVERAGE(D2:D4))The first formula adds 500 and 270 and divides by 8 numbers, which gives 96.25. The second averages 100 and 90 and gives 95. The two answers differ because the ranges hold different numbers of values. Use the first form when you want every number to count equally. Use the second only when each range should carry equal weight.
MIN and MAX do not have this problem, because the smallest value in a pool is the same however you split it.
=MAX(B2:B6, D2:D6)
=MIN(B2:B6, D2:D6)
=COUNT(B2:B6, D2:D6, 100)These return 140, 60, and 11.
Typed constants and references are treated differently
The functions apply different rules to a value typed directly into the formula than to a value found in a cell.
- A value typed into the formula is coerced. Text that looks like a number is converted, and
TRUEcounts as 1 andFALSEas 0. - A value found through a reference is not coerced. Text and logical values in referenced cells are ignored.
=SUM("3", TRUE, 2)This returns 6. Now suppose E2 holds the logical value TRUE and E3 holds the text 3.
=SUM(E2, E3)
=SUM(E2:E3)Both return 0. Single-cell references follow the same rule as ranges, so passing cells one at a time does not change the result.
Typed text that cannot become a number behaves differently across functions. =SUM("x") returns #VALUE!. =COUNT(1, "2", TRUE, "x") returns 3, because COUNT counts the three convertible values and ignores the text it cannot convert.
Overlapping ranges count cells twice
Excel does not remove duplicates between arguments. If two arguments cover the same cell, the cell is counted twice.
=SUM(B2:B6, B4:B6)This returns 500 plus 300, which is 800. The overlap is easy to create by accident. It often happens when you extend a formula by adding a range that is already partly covered. When a total looks too large, list the arguments and check whether any cells appear in more than one.
Whole-column and whole-row references
A reference such as B:B means every cell in column B, and 5:5 means every cell in row 5. The formula keeps working as rows are added, because there is no end row to maintain.
=SUM(B:B)
=AVERAGE(B:B)
=MAX(B:B)
=COUNT(B:B)
=COUNTA(A:A)-1With the sample data, these return 500, 100, 140, 5, and 5. The header text "Q1" in B1 is a text value in a range, so SUM, AVERAGE, MAX, and COUNT skip it. The last formula counts the filled cells in column A and subtracts 1 for the header.
Excel stores only the part of a sheet that holds data, so SUM and the other functions in this chapter do not slow down on B:B. Heavy formulas that loop over every cell, and some functions that evaluate an entire column as an array, can be slow. The two traps below are more likely to cause problems than speed.
Trap 1: the formula sits inside its own column
If you type =SUM(B:B) in any cell of column B, the range includes the formula's own cell. Excel reports a circular reference and the result is wrong. Put the formula in another column, or use a bounded range such as B2:B6.
Trap 2: a total row is inside the column
Suppose B7 holds =SUM(B2:B6), which is 500. A formula in F1 that reads =SUM(B:B) now returns 1000, because the column contains both the data and its total. The same mistake distorts AVERAGE, MAX, and COUNT. The total is included as one more data point.
Where whole columns do not belong
COUNTBLANK on a whole column counts all 1,048,576 rows minus the filled ones, which is almost never the answer you wanted. For a blank count, use a bounded range that matches your data.
Ranges across sheets
A range on another sheet is just another argument. Prefix it with the sheet name.
=SUM(B2:B6, Sheet2!B2:B6)If sheet names contain spaces, put them in single quotes, as in 'Q1 Data'!B2:B6.
When several sheets have the same layout, a 3D reference covers the same range on a run of sheets. Jan:Mar means every sheet from the tab named Jan through the tab named Mar, in tab order.
=SUM(Jan:Mar!B2:B6)
=AVERAGE(Jan:Mar!B2:B6)SUM, AVERAGE, MIN, MAX, and COUNT all accept 3D references. Moving a sheet in or out of the span changes the result, so check the tab order after reorganizing a workbook.
Choosing an approach
| Situation | Better choice |
|---|---|
| Data stays in a fixed block | A bounded range such as `B2:B6` |
| Rows are added regularly and the column holds only data | `B:B`, or an Excel table column |
| Values live in separate blocks | One call with several range arguments |
| Equal weight per range is required | Average the individual averages |
| A fixed adjustment is needed | A reference to a labeled input cell |
Common errors
- A total that looks too large. Check for overlapping arguments, or a total row inside a whole-column reference.
- A circular reference warning. The formula sits inside a range it reads.
- An AVERAGE that differs from expectations. Check whether pooling or averaging averages is what you meant.
- A SUM that ignores a number. The number may be stored as text in a referenced cell. Typed constants are converted, but cell contents are not.
- A
#VALUE!from a typed constant. The formula contains text that cannot become a number.
Exercise
Column B holds 500 in total across B2:B6, and a total row in B7 contains =SUM(B2:B6). A cell in column F holds =SUM(B:B). What does F return, and how would you fix it?
Show answer
It returns 1000, because B:B includes the total in B7 as well as the five data cells. Fix it by using the bounded range B2:B6, or by moving the total row out of column B so the column holds only data.
Exercise
With the sample data, what does =AVERAGE(B2:B6, D2:D4) return, and why does it differ from =AVERAGE(AVERAGE(B2:B6), AVERAGE(D2:D4))?
Show answer
It returns 96.25, which is (500 + 270) / 8. The second formula returns 95, the mean of 100 and 90. The first pools all eight numbers, so the larger Q1 range carries more weight. The second gives each range equal weight.
Exercise
E2 contains the logical value TRUE. What do =SUM(E2) and =SUM(TRUE) return?
Show answer
=SUM(E2) returns 0, because logical values found through a reference are ignored. =SUM(TRUE) returns 1, because a logical value typed directly into the formula is converted to a number.