Microsoft KB Archive/26698

{|
 * width="100%"|

XL: How to Count the Occurrences of a Number/Text in a Range

 * }

-

The information in this article applies to:


 * Microsoft Excel for Windows, versions 4.0, 4.0a, 5.0, 5.0c
 * Microsoft Excel for Windows, version 7.0
 * Microsoft Excel 97 for Windows
 * Microsoft Excel for the Macintosh, versions 1.x, 2.2, 3.0, 4.0, 5.0, 5.0a
 * Microsoft Excel 98 Macintosh Edition

-

SUMMARY
In Microsoft Excel, you can use worksheet functions to count the number of occurrences of a specific number or text string in a range of cells on a worksheet. The &quot;More Information&quot; section of this article contains sample formulas you can use to do this.

MORE INFORMATION
In the cell you want the result to appear in, enter the appropriate formula from the following examples.

To Count the Occurrences of a Number
Use this formula

  =SUM(IF( = ,1,0)) where is the range you want to search and is the number you want to find.

To Count the Occurrences of a Text String
Use this formula

  =SUM(IF( =&quot; &quot;,1,0)) where is the range you want to search and is the text you want to find (the text must be enclosed in quotation marks).

NOTE: The above formulas must be entered as array formulas. To enter a formula as an array formula in Microsoft Excel for Windows, press CTRL+SHIFT+ENTER. In Microsoft Excel for the Macintosh, press COMMAND+ENTER.

To Count the Occurrences of a Text String (Version 5.0 and Later)
Use the COUNTIF function to count the occurrences of a text string. For example, use the formula

  =COUNTIF( ,&quot; &quot;) where is the rang of cells you are evaluating and is the text string you want to count instances of (note that must be enclosed in quotation marks).

NOTE: The above formula must be entered as an array formula. To enter a formula as an array formula in Microsoft Excel for Windows, press CTRL+SHIFT+ENTER. In Microsoft Excel for the Macintosh, press COMMAND+ENTER.

Wildcard characters can be used within the COUNTIF function.

The asterisk character (*) represents more than one character. For example, to count all the cells in the range a1:a10 that contained an &quot;x,&quot; we can use the following formula:

  =COUNTIF(a1:a10,&quot;*x*&quot;) The question mark character (?) can also be used to represent one wildcard character. For example, to count all cells in the range whose second character is the letter, such as &quot;ax&quot; or &quot;bx.&quot;

  =COUNTIF(a1:a10,&quot;?x*&quot;) Additional query words: howto answer XL98 XL97 XL7 XL5 XL4 XL3

Keywords :

Version : MACINTOSH:1.x,2.2,3.0,4.0,5.0,5.0a,98; WINDOWS:4.0,4.0a,5.0,5.0c,97; Win95:7.0

Platform : MACINTOSH Win95 WINDOWS

Issue type : kbhowto

Technology : kbvcSearch