Page 302 - Excel 2007 Bible
P. 302

19_044039 ch14.qxp  11/21/06  11:06 AM  Page 259
                                       FIGURE 14.4
                                     This worksheet demonstrates various ways to count characters in a range.
                                             Entire cell contents                   Creating Formulas That Count and Sum     14
                                             To count the number of cells containing the contents of the Text cell (and nothing else), you can use the
                                             COUNTIF function as the following formula demonstrates.
                                                 =COUNTIF(Data,Text)
                                             For example, if the Text cell contains the string “Alpha”, the formula returns 2 because two cells in the Data
                                             range contain this text. This formula is not case sensitive, so it counts both “Alpha” (cell A2) and “alpha”
                                             (cell A10). Note, however, that it does not count the cell that contains “Alpha Beta” (cell A8).
                                             The following array formula is similar to the preceding formula, but this one is case sensitive:
                                                 {=SUM(IF(EXACT(Data,Text),1))}
                                             Partial cell contents
                                             To count the number of cells that contain a string that includes the contents of the Text cell, use this formula:
                                                 =COUNTIF(Data,”*”&Text&”*”)
                                             For example, if the Text cell contains the text “Alpha”, the formula returns 3 because three cells in the Data
                                             range contain the text “alpha” (cells A2, A8, and A10). Note that the comparison is not case sensitive.
                                             If you need a case-sensitive count, you can use the following array formula:
                                                 {=SUM(IF(LEN(Data)-LEN(SUBSTITUTE(Data,Text,””))>0,1))}
                                             If the Text cells contain the text “Alpha”, the preceding formula returns 2 because the string appears in two
                                            cells (A2 and A8).







                                                                                                                      259
   297   298   299   300   301   302   303   304   305   306   307