Sub topic 11
How blanks, text, logical values, and zeros affect results
This chapter explains how SUM, AVERAGE, MIN, MAX, COUNT, COUNTA, and COUNTBLANK treat the different kinds of content a cell can hold. It assumes you can write a basic formula over a range, such as =SUM(B2:B6). It also assumes you know what the function arguments are. Most surprising results in real worksheets come from the rules below, not from the formulas themselves.
The core rule: references and typed values are treated differently
Excel applies two sets of rules, depending on how a value reaches the function.
- Reference arguments are cell addresses or ranges, such as
B2:B8. Excel reads the cell contents and keeps only the numbers. Text, logical values (TRUEandFALSE), and empty cells are skipped. - Typed arguments are values written directly in the formula, such as
"5"orTRUE. Excel tries to convert them. The text"5"becomes the number 5,TRUEbecomes 1, andFALSEbecomes 0.
Dates and times count as numbers in both cases, because Excel stores them as serial numbers.
A test range
The examples in this chapter use the range B2:B8.
| Cell | Content | What it is |
|---|---|---|
| B2 | 10 | Number |
| B3 | 20 | Number |
| B4 | (nothing) | Empty cell |
| B5 | n/a | Text |
| B6 | 0 | Number (zero) |
| B7 | 15 | Number stored as text (entered as `'15`) |
| B8 | TRUE | Logical value |
Here are the results over this range.
=SUM(B2:B8)
=AVERAGE(B2:B8)
=MIN(B2:B8)
=MAX(B2:B8)
=COUNT(B2:B8)
=COUNTA(B2:B8)
=COUNTBLANK(B2:B8)| Formula | Result | Why |
|---|---|---|
| `SUM` | 30 | Adds 10, 20, and 0. The text, the text-number, and `TRUE` are skipped. |
| `AVERAGE` | 10 | 30 divided by 3 numeric cells. The empty cell does not count. |
| `MIN` | 0 | The zero is a real number and is the smallest. |
| `MAX` | 20 | Largest numeric value. |
| `COUNT` | 3 | Only B2, B3, and B6 are numbers. |
| `COUNTA` | 6 | Every non-empty cell, including text and `TRUE`. |
| `COUNTBLANK` | 1 | Only B4 is empty. |
The cell classification that drives these results looks like this.
Blanks versus zeros
An empty cell and a cell containing 0 look similar but behave differently. AVERAGE shows the difference most clearly.
=AVERAGE(B2:B4)Suppose B2 is 10, B3 is 20, and B4 is empty. The result is 15, because only two cells are numeric. If B4 contains 0, the result is 10, because the sum of 30 is divided by 3.
Neither answer is wrong. The question is whether a missing reading means "nothing was measured" (leave it empty) or "the measured value was zero" (enter 0). Enter data to match the meaning you intend.
MIN is affected in the same way. An empty cell cannot be the minimum, but a zero can.
Text and numbers stored as text
Text in a range is skipped by SUM, AVERAGE, MIN, MAX, and COUNT. This is useful when a column has a header or a note such as "n/a". It is a problem when a number is stored as text.
Numbers become text when you import data, paste from a web page, or type an apostrophe before a value. The cell usually has a small green triangle in its corner, and its content aligns to the left by default. SUM and COUNT skip it silently, and no error appears. The total is just too small.
You can detect the problem by comparing two counts.
=COUNTA(B2:B8)-COUNT(B2:B8)This returns the number of non-empty cells that are not numeric. In the test range it returns 3 (the text n/a, the text-number, and TRUE). A result above zero in a column that should hold only numbers is a warning sign.
To fix text-numbers, use Data > Text to Columns on the column and finish with the default settings. You can also multiply the cells by 1 in a helper column. The error-check smart tag also offers "Convert to Number".
Logical values
In a range, TRUE and FALSE are ignored by the math functions and by COUNT. COUNTA counts them, because they are cell contents.
Typed directly, they convert to 1 and 0.
=SUM(10, "5", TRUE)
=SUM(B8, 1)The first formula returns 16, because the typed "5" becomes 5 and the typed TRUE becomes 1. The second returns 1, because B8 is a reference, so its TRUE is skipped.
The same distinction applies to COUNT.
=COUNT(10, "5", TRUE, "abc")This returns 3. The 10, the text "5", and TRUE are counted. The text "abc" is not. In the math functions, however, typed text that cannot be converted does not get skipped.
=SUM(10, "abc")This returns #VALUE!.
Typed arguments like these are rare in real work. The rule matters mostly when a formula returns TRUE or FALSE and you pass that result in directly. For example, =SUM(A1>5, 2) returns 3 when A1 is greater than 5, because the comparison is a typed value, not a cell reference.
Formulas that return empty text
A formula can return "", which is text with no characters.
=IF(A2="", "", A2*1.2)For rows where A2 is empty, this cell looks blank but holds text. The consequences differ by function.
SUM,AVERAGE,MIN,MAX, andCOUNTskip it, because it is text.COUNTAcounts it, because the cell is not truly empty.COUNTBLANKalso counts it, because Excel treats""as blank for this function.
So COUNTA and COUNTBLANK can both include the same cell. A cell holding only a space (" ") is also text. COUNTBLANK does not count it, but COUNTA does.
Errors in a range
An error value such as #N/A or #DIV/0! in a cell is not skipped. It passes through.
| Function | Result when one cell in the range is an error |
|---|---|
| `SUM`, `AVERAGE`, `MIN`, `MAX` | Returns that error |
| `COUNT` | Skips the cell |
| `COUNTA` | Counts the cell |
| `COUNTBLANK` | Skips the cell |
One bad cell can therefore turn a whole summary into an error. Find the source cell with Formulas > Error Checking, or by using Go To Special > Formulas > Errors. The next chapter covers guarding formulas against this.
Results when no numbers qualify
If the range holds no numbers, the functions diverge.
=SUM(C2:C6)
=MIN(C2:C6)
=MAX(C2:C6)
=COUNT(C2:C6)
=AVERAGE(C2:C6)Suppose C2:C6 is empty or all text. The first four return 0. AVERAGE returns #DIV/0!, because it divides by a count of zero.
A MIN or MAX of 0 is therefore ambiguous. It can mean "the smallest value is zero" or "there were no numbers". When the difference matters, check COUNT first.
Quick reference
| Content in a range | SUM, AVERAGE, MIN, MAX | COUNT | COUNTA | COUNTBLANK |
|---|---|---|---|---|
| Number or date | Used | Counted | Counted | No |
| Zero | Used | Counted | Counted | No |
| Number stored as text | Skipped | No | Counted | No |
| Text | Skipped | No | Counted | No |
| `TRUE` or `FALSE` | Skipped | No | Counted | No |
| Empty cell | Skipped | No | No | Counted |
| Formula returning `""` | Skipped | No | Counted | Counted |
| Error value | Returns the error | No | Counted | No |
Exercise
The range D2:D6 holds 8, 12, an empty cell, the text "pending", and the number 0. What do SUM, AVERAGE, MIN, COUNT, COUNTA, and COUNTBLANK return? Which result would change if the empty cell were replaced by 0?
Show answer
SUM is 20 (8 + 12 + 0). AVERAGE is 20/3, about 6.67, because three cells are numeric. MIN is 0. COUNT is 3. COUNTA is 4 (everything except the empty cell). COUNTBLANK is 1. If the empty cell became 0, AVERAGE would become 5 (20/4), COUNT would become 4, COUNTA would become 5, and COUNTBLANK would become 0. SUM and MIN would not change.
Exercise
A column of imported prices gives =SUM(E2:E100) a result of 4,200, but the total should be near 5,000. =COUNT(E2:E100) returns 84 and =COUNTA(E2:E100) returns 99. What is the likely cause, and how can you confirm and fix it?
Show answer
About 15 cells are non-empty but not numeric, most likely numbers stored as text. Confirm it with =COUNTA(E2:E100)-COUNT(E2:E100), which returns 15, and by looking for green triangles or left-aligned values. Fix it by converting the cells to numbers, for example with Data > Text to Columns or the "Convert to Number" smart tag. The SUM then includes them.