In the previous post, we talked that how to count cell that contain certain text using the COUNTIF function in Excel.
This post will guide you how to count the number of cells that do not contain specific text within a range of cells using a formula in Excel 2013/2016 or Excel 365. How do I count the number of cells without certain text using a simple formula in Excel. When you analyze a large list of data, you may also want to know that how many cells that do not contain specific text. The below steps will show you how to do it in a simple way.
Table of Contents
1. Count Number of Cells that do Not Contain Specific Text Using COUNTIF Function
You can use the COUNTIF function to count cells that do not contain certain text. And you also need to supply the target text string in the criteria argument in the COUNTIF function.
The below is a generic formula to count the number of cells that do not contain specific text:
Assuming that you have a list of data in range B1:B6 and you want to count the number of cells without a certain text “exc”. And you can type this string in the second argument as its criteria and you will get the below formula:
LET’S SEE THAT HOW THIS FORMULA WORKS:
The COUNTIF function can be used to count the number of cells that match a single condition or criteria. And in this case, you need to provide a criteria as “<>*exc*”, which is evaluated as “values that do not contain ‘exc’ in any position”. Then the total count of all cells in the range B1:B6 that meet the above criteria is returned.
Note: the asterisk(*) means that it will match any number of characters in the above formula. If you just only supply a certain string “exc”, it means that cells must contain exactly “exc”.
If the cell contains any other characters, it will not be counted. So you need to use the asterisk character as a wildcard in the second criteria argument.
The “<>” operator means that does not equal to a certain value, so the above formula can be used to count any cell that does not contain “exc” in any position in cells.
2. Count Number of Cells that do Not Contain Specific Text With VBA Code
You can also use a User-defined function with VBA code to count number of cells that do not contain a specific text string in Excel, just do the following steps:
Step1: Press Alt + F11 to open the Visual Basic Editor.
Step2: In the Visual Basic Editor, click on Insert > Module.
Step3: In the new module, enter the following code:
Function CountNotEqual_ExcelHow(rng As Range, criteria As String) As Long CountNotEqual_ExcelHow = WorksheetFunction.CountIf(rng, "<>*" & criteria & "*") End Function
Step4: Save the module with a suitable name, such as “CountNotEqual_ExcelHow“. And return to your worksheet, and enter a cell where you want to use the user-defined function.
Step5: In any blank cell, enter the formula:
Where ” B1:B6” is the range you want to count and “exc” is the specific text you want to exclude.
Step6: Press Enter, and the formula will return the count of cells that do not contain the specific text.
Note that in the user-defined function code, the “&” symbol is used to concatenate the “<>” operator with the criteria string entered by the user.
3. Video: Count Number of Cells that do Not Contain Specific Text
This video will demonstrate two methods to count cells that do not contain specific text in Excel – using the COUNTIF function and VBA code.
4. Related Functions
- Excel COUNTIF function
The Excel COUNTIF function will count the number of cells in a range that meet a given criteria. This function can be used to count the different kinds of cells with number, date, text values, blank, non-blanks, or containing specific characters. etc. = COUNTIF (range, criteria) …