Menu

COUNTIF Not Blank in Excel: Count Non-Empty Cells

=COUNTIF(B2:B8,"<>") counts the cells in B2:B8 that are not empty, the same as COUNTA. Add other conditions with COUNTIFS, and handle cells that only look empty.

Every sheet on this page is live: change a number or a formula and it recalculates.

=COUNTIF(B2:B8,"<>") counts the cells in B2:B8 that are not empty. <> means "not equal to", and with nothing after it the comparison is with an empty cell. =COUNTA(B2:B8) gives the same number.

Count filled cells
F2
ABCDEF
1NameEmailPhoneCountResult
2Anaana@mail.com555-0101Emails, COUNTIF5
3Ben555-0102Emails, COUNTA5
4Caracara@mail.comMissing emails2
5Dandan@mail.com555-0104Phones4
6EvaRows7
7Finnfinn@mail.com555-0106
8Gusgus@mail.com
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Five of the seven contacts have an email, so F2 and F3 both show 5, and COUNTBLANK counts the two missing ones. The filled and empty counts always add up to the number of rows in F6. Type an email into B3 and F2 goes up by one while F4 goes down.

COUNTIF not blank vs COUNTA

For one range, =COUNTIF(B2:B8,"<>") and =COUNTA(B2:B8) count the same cells: anything that is not empty, including numbers, dates, TRUE/FALSE and error values. COUNTA is shorter. The "<>" form exists for the moment you need a second condition, because COUNTA cannot take one and COUNTIFS can.

COUNT is a different function: it counts only numbers and dates, so a column of names gives 0. The three are compared on COUNT and COUNTA.

The opposite of not blank is "": =COUNTIF(B2:B8,"") counts the empty cells, like COUNTBLANK.

COUNTIFS not blank with another condition

Use "<>" as one of the COUNTIFS criteria. Below, a ship date means the order has gone out.

Not blank plus a condition
F2
ABCDEF
1RegionOrderShippedConditionCount
2NorthA-1012026-01-08North, shipped2
3SouthA-102North, not shipped1
4NorthA-1032026-02-06Any region, shipped3
5EastA-1042026-02-20Order and date filled3
6SouthA-105
7NorthA-106
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

F2 counts the two North orders with a date, F3 the one without. F5 puts "<>" on two columns, so it counts the rows where both are filled. The same criterion works in SUMIFS and AVERAGEIFS: =SUMIFS(D2:D7,C2:C7,"<>") would add an amount column D for the shipped rows only.

Cells that only look empty

A cell with a space in it looks empty but holds text, and "<>" and COUNTA count it. That happens with data pasted from other systems or "cleared" by typing a space. Count the cells with visible content by trimming the spaces and checking the length.

A space is not empty
E2
ABCDE
1NameNoteCountResult
2Anacall backCOUNTA4
3Ben Visible content2
4CaraSpace in B3?1
5Danpaid
6Eva
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

B3 holds one space and B6 two. COUNTA counts them with the two real notes and shows 4. The SUMPRODUCT version trims each cell and counts only those with something left: 2. To clean the cells themselves, select them and press Delete, or use TRIM in a helper column. Replacing every space with nothing in Find and Replace would also turn "call back" into "callback".

Formulas that return an empty string

A formula like =IF(C2>0,C2,"") shows nothing when the condition is false, but the cell is not empty: it holds a formula whose result is an empty string. Different counting functions treat it differently. For A2:A6 holding Apple, a formula returning "", an empty cell, 5 and Pear, Excel gives:

=COUNTA(A2:A6)                   4   counts the "" formula
=COUNTIF(A2:A6,"<>")             4   counts the "" formula
=COUNTBLANK(A2:A6)               2   counts the "" formula as blank
=COUNTIF(A2:A6,"")               2   counts the "" formula as blank
=SUMPRODUCT(--(LEN(A2:A6)>0))    3   counts only visible content
=COUNTIF(A2:A6,"?*")             2   counts text of at least one character

So the formula's cell is counted both as blank and as not blank, and COUNTA plus COUNTBLANK is more than the number of cells. When a column is filled with such formulas, count with =SUMPRODUCT(--(LEN(A2:A6)>0)), which counts only cells that show something. With a second condition: =SUMPRODUCT((B2:B6="North")*(LEN(A2:A6)>0)).

Practice: not blank plus a condition

Your turn: Paris contacts with a phone
F2
ABCDEF
1NameCityPhoneCountResult
2AnaParis555-0101Paris with phone
3BenLyon555-0102
4CaraParis
5DanParis555-0104
6EvaLyon
7FinnNice555-0106
8GusParis
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Your turn: Count the contacts in Paris that have a phone number in column C. Write the formula in F2.

Which formula to use

You want to countFormula
Filled cells in one range=COUNTA(B2:B8)
Filled cells plus another condition=COUNTIFS(A2:A8,"North",B2:B8,"<>")
Rows where two columns are filled=COUNTIFS(B2:B8,"<>",C2:C8,"<>")
Cells with visible content, skipping spaces and "" formulas=SUMPRODUCT(--(LEN(TRIM(B2:B8))>0))
Filled text cells only=COUNTIF(B2:B8,"?*")
Empty cells=COUNTBLANK(B2:B8)

To test a single cell instead of counting, =B2<>"" returns TRUE when B2 shows something, and =ISBLANK(B2) returns TRUE only when B2 is truly empty, with no formula in it.

Frequently Asked Questions

Is COUNTIF "<>" the same as COUNTA?

For one range, yes: =COUNTIF(B2:B8,"<>") and =COUNTA(B2:B8) count the same cells (text, numbers, dates, TRUE/FALSE and errors). The "<>" form is for COUNTIFS, where it can sit next to another condition.

What does "<>" mean in COUNTIF?

<> is "not equal to", and with nothing after it the comparison is with an empty cell. So "<>" means "not empty", and "<>North" means "not equal to North".

How do I count cells that are not blank and not zero?

Use =COUNTIFS(B2:B8,"<>",B2:B8,"<>0"). The criterion "<>0" on its own also counts empty cells, because an empty cell is not equal to 0; adding "<>" leaves them out.

Why does COUNTA count cells that look empty?

They are not empty: they hold a space, or a formula that returns an empty string "". To count only cells with visible content, use =SUMPRODUCT(--(LEN(TRIM(B2:B8))>0)).

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED