How to use the COUNTBLANK function
The COUNTBLANK function counts empty or blank cells in a range.
The picture above demonstrates the COUNTBLANK function entered in cell F3. The evaluated range is C3:C10, two of the cells contains formulas, three cells seem to be empty but only one is in fact empty.
Cell C4 has a formula that returns a blank, note that the COUNTBLANK function considers this cell empty. Cell C7 has a space character and is therefore counted. Only cell C6 is really empty.
Use the TRIM function to remove space characters.
Table of Contents
1. COUNTBLANK Function Syntax
COUNTBLANK(value1, [value2], ...)
2. COUNTBLANK Function Arguments
value1 | Required. A cell reference to a range for which you want to count empty cells. |
[value2] | Optional. Up to 254 additional arguments like the one above. |
The COUNTBLANK function counts errors as not empty.
3. COUNTBLANK Function example
The formula in cell F3 counts two empty cells in cell range C3:C10. Note, there is also one error value meaning the COUNTBLANK function works with error values as well.
Formula in cell F3:
Explaining formula
COUNTBLANK(C3:C10)
becomes
COUNTBLANK({"A";"";44;0;" ";TRUE;#DIV/0!;"Text"})
and returns 2.
Cell C7 is not empty, it contains a space character. Cell C4 contains a formula, however, the output is nothing. The COUNTBLANK function counts cell C4 as empty.
4. Count blanks - arrays and other functions
This example shows that you can't use hardcoded arrays in the COUNTBLANK function, a dialog box appears telling you there is a problem with the formula.
Formula in cell C3:
You can't use other functions in the COUNTBLANK function, unexpected things may happen.
5. Count blanks based on a condition
Formula in cell C3:
Explaining formula
Step 1 - Check values against a condition
The equal sign lets you compare value to value, you can also compare value to multiple values, and the result is an array.
The equal sign is a logical operator and the result is a boolean value TRUE or FALSE.
B3:B11=E3
becomes
{"Pen"; "Pencil"; "Clip"; "Pen"; "Clip"; "Pencil"; "Pen"; "Clip"; "Clip"}="Clip"
and returns
{FALSE; FALSE; TRUE; FALSE; TRUE; FALSE; FALSE; TRUE; TRUE}.
Step 2 - Filter values based on a condition
The FILTER function extracts values/rows based on a condition or criteria.
Function syntax: FILTER(array, include, [if_empty])
FILTER(C3:C11,B3:B11=E3)
becomes
FILTER(C3:C11,{FALSE; FALSE; TRUE; FALSE; TRUE; FALSE; FALSE; TRUE; TRUE})
becomes
FILTER({"";7;45;31;"";37;98;"";6}, {FALSE; FALSE; TRUE; FALSE; TRUE; FALSE; FALSE; TRUE; TRUE})
and returns
{45; ""; ""; 6}.
Step 3 - Find blank values
FILTER(C3:C11,B3:B11=E3)=""
becomes
{45; ""; ""; 6}=""
and returns
{FALSE; TRUE; TRUE; FALSE}.
Step 5 - Add boolean values
The SUM function allows you to add numerical values, the function returns the sum in the cell it is entered in. The SUM function is cleverly designed to ignore text and boolean values, adding only numbers.
Function syntax: SUM(number1, [number2], ...)
SUM((FILTER(C3:C11,B3:B11=E3)="")*1)
becomes
SUM({FALSE; TRUE; TRUE; FALSE})
and returns 2.
FALSE is 0 (zero) and TRUE is 1.
6. Count blanks based on a list
Formula in cell C3:
Explaining formula
Step 1 -
COUNTIF(E3:E4,B3:B11)
Step 2 -
FILTER(C3:C11,COUNTIF(E3:E4,B3:B11))
Step 3 -
FILTER(C3:C11,COUNTIF(E3:E4,B3:B11))=""
Step 4 -
(FILTER(C3:C11,COUNTIF(E3:E4,B3:B11))="")*1
Step 5 -
SUM((FILTER(C3:C11,COUNTIF(E3:E4,B3:B11))="")*1)
7. Count blanks in a delimited text string
Formula in cell C3:
Explaining formula
Step 1 -
TEXTSPLIT(C3,";")
Step 2 -
TEXTSPLIT(C3,";")=""
Step 3 -
(TEXTSPLIT(C3,";")="")*1
Step 4 -
SUM((TEXTSPLIT(C3,";")="")*1)
8. Count blanks in multiple cell ranges
Formula in cell B12:
Explaining formula
Step 1 - Join arrays
VSTACK(B3:B9,D3:D9,F3:F9)
Step 2 - Check if empty
VSTACK(B3:B9,D3:D9,F3:F9)=""
Step 3 - Convert boolean values to numbers
(VSTACK(B3:B9,D3:D9,F3:F9)="")*1
Step 4 - Calculate a total
SUM((VSTACK(B3:B9,D3:D9,F3:F9)="")*1)
9. Count blank cells ignoring space characters
The following formula counts blank cells even if the cell contains one or more space characters.
Array formula in cell D5:
To enter an array formula, type the formula in a cell then press and hold CTRL + SHIFT simultaneously, now press Enter once. Release all keys.
The formula bar now shows the formula with a beginning and ending curly bracket telling you that you entered the formula successfully. Don't enter the curly brackets yourself.
Explaining formula in cell D5
Step 1 - Remove leading and trailing space characters
The TRIM function deletes leading and trailing space characters from a cell value, however, here I am using a cell range so we need to enter this formula as an array formula.
TRIM(B3:B14)
becomes
TRIM({"ZF";"";"5";"T5";" ";#N/A;"SK";"JK";"";"DP";"3";#DIV/0!})
and returns
{"ZF";"";"5";"T5";"";#N/A;"SK";"JK";"";"DP";"3";#DIV/0!}
Step 2 - Convert error values to a valid value
Also, the TRIM function doesn't ignore error values, we need to trap those error values before counting them and the IFERROR function allows you to do that.
becomes
IFERROR({"ZF";"";"5";"T5";"";#N/A;"SK";"JK";"";"DP";"3";#DIV/0!},"A")
and returns {"ZF";"";"5";"T5";"";#N/A;"SK";"JK";"";"DP";"3";#DIV/0!}.
I have entered the array in column A.
Step 3 - Compare each value in the array to nothing
The equal sign lets you compare the values in the array to a given condition, in this case "" is nothing.
becomes
{"ZF";"";"5";"T5";"";"A";"SK";"JK";"";"DP";"3";"A"}=""
and returns {FALSE; TRUE; FALSE; FALSE; TRUE; FALSE; FALSE; FALSE; TRUE; FALSE; FALSE; FALSE}.
I have entered the array in column A.
Step 4 - Convert boolean values
The SUM function can't add boolean values in an array, we need to convert them. TRUE becomes 1 and FALSE becomes 0 (zero).
(IFERROR(TRIM(B3:B14),"A")="")*1
becomes
({FALSE; TRUE; FALSE; FALSE; TRUE; FALSE; FALSE; FALSE; TRUE; FALSE; FALSE; FALSE})*1
and returns {0; 1; 0; 0; 1; 0; 0; 0; 1; 0; 0; 0}.
I have entered the array in column A.
Step 5 - Sum values
SUM((IFERROR(TRIM(B3:B14),"A")="")*1)
becomes
SUM({0; 1; 0; 0; 1; 0; 0; 0; 1; 0; 0; 0}) and returns 3 in cell D5.
'COUNTBLANK' function examples
The following article has a formula that contains the COUNTBLANK function.
Functions in 'Statistical' category
The COUNTBLANK function function is one of 74 functions in the 'Statistical' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form