XL: Counting Cells in a Range that Contain Text String

Last reviewed: August 20, 1997
Article ID: Q28262

SUMMARY

To count the number of cells in a range that contain a particular character or characters, use the following array formula in a single cell (array formulas must be entered by pressing COMMAND+ENTER):

   =SUM(IF(NOT(ISERROR(SEARCH("search text",range))),1))

This formula searches for the occurrence of the search text in a cell, returns #VALUE! if an occurrence is not found, and then counts the number of nonerror values.

For example, suppose you want to search for the text "my" in the following range of cells:

   +---+---------+
   |   |    A    |
   +---+---------+
   | 1 | mytext  |
   +---+---------+
   | 2 | text    |
   +---+---------+
   | 3 | textmy  |
   +---+---------+
   | 4 | temyxt  |
   +---+---------+

The formula =SUM(IF(NOT(ISERROR(SEARCH("my",$A$1:$A$4))),1)) will return a value of 3 because "my" occurs three times in the range A1:A4.


Additional reference words: 1.00 1.03 1.04 1.06 1.50 2.20 3.00


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 20, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.