COUNTIF Function to Count Cells That Are Not Equal to Zero

Let’s use the Sales Report of a particular grocery store. This dataset contains the names of the Sales Rep, the Product Name, and their respective Sales under columns B, C, and D. We’ll use the COUNTIF function to count cells that are not equal to zero.

countif not equal to zero


Method 1 – Counting with Blank Cells

There are two blank cells and two cells having zero values in the Sales column. We’ll count the blank cells as having non-zero values.

Steps:

  • Select cell D16 and enter the following formula:
=COUNTIF(D5:D14,“<>0”)

Here, D5:D14 is the range where the function works. And “<>0” is the criteria. So, the function counts the cells having non-zero values in the above range.

  • Press Enter.

Counting with Blank Cells

There are a total of 8 cells in the Sales column, including blank cells and cells with non-zero values.

Read More: Excel COUNTIF to Count Cells Greater Than 1


Method 2 – Counting Without Blank Cells

Steps:

  • Go to cell D16 and insert the formula below:
=COUNTA(D5:D14)-COUNTIF(D5:D14,"=0")

Here, the COUNTA function counts all the visible cells in the D5:D14 range. It returns 8. Then, the COUNTIF function counts the number of cells having a zero value in the D5:D14 range. It returns 2. After that, we subtract this output from the first output. Therefore, the final result is 6.

  • Hit Enter.

Counting Without Blank Cells

Read More: COUNTIF Between Two Cell Values in Excel


Method 3 – Counting Cells with Non-Zero Number Values

Steps:

  • Select D16 and insert the following formula:
=COUNTIF(B5:D14,"<0")+COUNTIF(B5:D14,">0")

In this formula, the COUNTIF function counts the cells with a value less than zero and a value greater than zero. So, we’ll just get the number of cells having Number values. In our dataset, there is no negative value. Thus, you can ignore the first part of the formula in this case.

  • Hit Enter.

Counting Cells with Number Values

Read More: How to Use COUNTIF for Non Contiguous Range in Excel


Method 4 – Using SUMPRODUCT and ISNUMBER Functions to Count Cells with Values

Steps:

  • Go to cell D16 and paste the following formula into it:
=SUMPRODUCT(--(ISNUMBER(B5:D14)),--(B5:D14<>0))

Here, B5:D14<>0 returns an array of TRUE/FALSE. Which cells are not equal to zero return TRUE as output. Others return FALSE. Then, the double hyphen () sign converts this array to an array of 0 and 1. It transforms TRUE to 1 and FALSE to 0.
Then, the ISNUMBER function checks whether a value is a number or not in the B5:D14 range. It also returns Boolean values in an array. We used the double hyphen to convert it to 1 and 0.
The SUMPRODUCT function returns the sum of the products of the corresponding values from the two arrays.

  • Hit Enter.

Using SUMPRODUCT and ISNUMBER Functions to Count Cells with Number Values

Read More: How to Compare Two Columns Using COUNTIF Function


Method 5 – Using the COUNTIF Function to Count Cells That Are Not Equal to Text

Steps:

  • Select cell D16 and insert the following formula into the Formula Bar.
=COUNTA(B5:D14)+COUNTBLANK(B5:D14)-COUNTIF(B5:D14,"*")

The COUNTA function counts all the visible cells in the B5:D14 range. The COUNTBLANK function counts the blank cells. We added those values up. The COUNTIF function counts all the cells with a text string of any length with the help of the asterisk (*) symbol. Subtracting this from the previous calculation gets the cells without any text values.

  • Hit Enter.

COUNTIF Function to Count Cells That Are Not Equal to Text

Read More: How to Use COUNTIF Function to Calculate Percentage in Excel


Method 6 – Using the COUNTIF Function to Count Cells That Are Not Equal to Blank

Steps:

  • Go to cell D16 and enter the formula below.
=COUNTIF(B5:D14,"<>")

The COUNTIF function counts the cells not equal to a blank string. The <> sign serves as “not-equal-to”. The function counts cells with this criterion in the B5:D14 range and returns the output as 28.

  • Hit Enter.

COUNTIF Function to Count Cells That Are Not Equal to Blank

Read More: How to Use COUNTIF Function with Array Criteria in Excel


Practice Section

We have provided a Practice section like the one below on each sheet on the right side.

Practice Section


Download the Practice Workbook


Related Articles


<< Go Back to Excel COUNTIF Function | Excel Functions | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Shahriar Abrar Rafid
Shahriar Abrar Rafid

Shahriar Abrar Rafid, BSc, Naval Architecture and Marine Engineering, Bangladesh University of Engineering and Technology, Bangladesh, has worked with the ExcelDemy project for more than 1 year. He has written over 100+ articles for ExcelDemy. He is a professional visual content developer adept at crafting scripts, meticulously editing Excel files, and delivering insightful video tutorials for YouTube channels. His work and learning interests vary from Microsoft Office Suites and Excel to Data Analysis, VBA, and Video recording and... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo