2
1/1/14, 7:27 PM Formulas to count the occurrences of text, characters, or words in Excel for Mac Page 1 of 2 http://support.microsoft.com/kb/187667  Article ID: 1876 67 - View products that this article applies to. This article was previously published under Q187667 This article contains formulas that calculate the following: The number of occurrences of a text string in a range of cells. The number of occurrences of a character in one cell. The number of occurrences of a character in a range of cells. The number of words (or text strings) separated by a character in a cell. Formula to count the number of occurrences of a text string in a range Use the following formula to count the number of occurrences of a text string in a range: =SUM(LEN(<range>)-LEN (SUBSTITUTE(<range>,"t ext","")))/LEN("text") where <range> is the cell range in question and "text" is replaced by the specific text string you want to count. Note The above formula must be entered as an array formula. To enter a formula as an array formula, press COMMAND+RETURN. The formula must be divided by the length of the text string because the sum of the character length of the range is decreased by a multiple of each occurrence of the text string. This formula can replace all later formulas in this article except the formula to count the number of words in a cell. Example 1: Counting the number of occurrences of a text string in a range 1. Start Microsoft Excel and open a new workbook. 2. Type the f ollowing on sheet1: NOTE: The above formula must be entered as an array formula. T o enter a formula as an array formula, press COMMAND+RETURN. The value of cell A8 is 4 because the text "apple" appears four times in the range. Formula to count the number of occurrences of a single character in one cell If you are concerned about searching for a single character in a single cell, the formula is simplified to: =LEN(<range>)-LEN(SUBSTITUTE(<range>,"a","")) where <range> is the cell range in question and "a" is replaced by the character you want to count. NOTE: This formula does not need to be entered as an array formula. Example 2: Counting the number of occurrences of a character in one cell Use the same data from the preceding example; assume you want to count the number of occurrences or the character "p" in A7. Type the following formula in cell  A9:  A9: =LEN(A7)-LEN( SUBSTITUTE(A7,"p","") ) The value of cell A9 is 3 because the character "p" appears three times in A7. Formula to count the number of occurrences of a single character in a range If you are concerned about searching for a single character in a range, the formula is simplified to: =SUM(LEN(range)-LEN(SUBSTITUTE(range,"a",""))) where <range> is the cell range in question and "a" is replaced by the character you want to count. Note The above formula must be entered as an array formula. To enter a formula as an array formula, press COMMAND+RETURN. Example 3: Counting the number of occurrences of a character in a range Use the same data from the preceding example; assume you want to count the number of occurrences or the character "p" in A2:A7. Type the following formula in cell A10:  A10: =SUM(LEN(A2: A7)-LEN(SUBSTITU TE(A2:A7,"p",""))) NOTE: The above formula must be entered as an array formula. To enter a formula as an array formula, press COMMAND+RETURN. The value of cell A10 is 11 because the character "p" appears eleven times in A2:A7. Formulas to count the occurrences of text, characters, or words in Excel for Mac SUMMARY MORE INFORMATION A1: Fruit A2: apple,apple A3: orange A4: apple,orange A5: grape A6: orange,grape A7: grape, apple A8: =SUM(LEN(A2:A7)-LEN(SUBSTITUTE(A2:A7,"apple", "")))/LEN("app le")

Formulas to Count the Occurrences of Text, Characters, Or Words in Excel for Mac

Embed Size (px)

Citation preview

Page 1: Formulas to Count the Occurrences of Text, Characters, Or Words in Excel for Mac

8/11/2019 Formulas to Count the Occurrences of Text, Characters, Or Words in Excel for Mac

http://slidepdf.com/reader/full/formulas-to-count-the-occurrences-of-text-characters-or-words-in-excel-for 1/2

1/1/14, 7:27 PMFormulas to count the occurrences of text, characters, or words in Excel for Mac

Page 1 of 2http://support.microsoft.com/kb/187667

 Article ID: 187667 - View products that this article applies to.

This article was previously published under Q187667

This article contains formulas that calculate the following:

The number of occurrences of a text string in a range of cells.The number of occurrences of a character in one cell.The number of occurrences of a character in a range of cells.The number of words (or text strings) separated by a character in a cell.

Formula to count the number of occurrences of a text string in a range

Use the following formula to count the number of occurrences of a text string in a range:=SUM(LEN(<range>)-LEN(SUBSTITUTE(<range>,"text","")))/LEN("text")

where <range> is the cell range in question and "text" is replaced by the specific text string you want to count.

Note The above formula must be entered as an array formula. To enter a formula as an array formula, press COMMAND+RETURN.

The formula must be divided by the length of the text string because the sum of the character length of the range is decreased by a multiple of each occurrence of the text string. This formula can replace all later formulas in this article except the formula to count the number of words in a cell.

Example 1: Counting the number of occurrences of a text string in a range

1. Start Microsoft Excel and open a new workbook.2. Type the following on sheet1:

NOTE: The above formula must be entered as an array formula. To enter a formula as an array formula, press COMMAND+RETURN.

The value of cell A8 is 4 because the text "apple" appears four times in the range.

Formula to count the number of occurrences of a single character in one cell

If you are concerned about searching for a single character in a single cell, the formula is simplified to:=LEN(<range>)-LEN(SUBSTITUTE(<range>,"a",""))

where <range> is the cell range in question and "a" is replaced by the character you want to count.

NOTE: This formula does not need to be entered as an array formula.

Example 2: Counting the number of occurrences of a character in one cell

Use the same data from the preceding example; assume you want to count the number of occurrences or the character "p" in A7. Type the following formula in cell A9:

 A9: =LEN(A7)-LEN(SUBSTITUTE(A7,"p",""))

The value of cell A9 is 3 because the character "p" appears three times in A7.

Formula to count the number of occurrences of a single character in a range

If you are concerned about searching for a single character in a range, the formula is simplified to:=SUM(LEN(range)-LEN(SUBSTITUTE(range,"a","")))

where <range> is the cell range in question and "a" is replaced by the character you want to count.

Note The above formula must be entered as an array formula. To enter a formula as an array formula, press COMMAND+RETURN.

Example 3: Counting the number of occurrences of a character in a range

Use the same data from the preceding example; assume you want to count the number of occurrences or the character "p" in A2:A7. Type the following formula incell A10:

 A10: =SUM(LEN(A2:A7)-LEN(SUBSTITUTE(A2:A7,"p","")))

NOTE: The above formula must be entered as an array formula. To enter a formula as an array formula, press COMMAND+RETURN.

The value of cell A10 is 11 because the character "p" appears eleven times in A2:A7.

Formulas to count the occurrences of text, characters,

or words in Excel for Mac

SUMMARY

MORE INFORMATION

A1: Fruit A2: apple,apple A3: orange A4: apple,orange A5: grape A6: orange,grape A7: grape, apple A8:

=SUM(LEN(A2:A7)-LEN(SUBSTITUTE(A2:A7,"apple","")))/LEN("apple")

Page 2: Formulas to Count the Occurrences of Text, Characters, Or Words in Excel for Mac

8/11/2019 Formulas to Count the Occurrences of Text, Characters, Or Words in Excel for Mac

http://slidepdf.com/reader/full/formulas-to-count-the-occurrences-of-text-characters-or-words-in-excel-for 2/2

1/1/14, 7:27 PMFormulas to count the occurrences of text, characters, or words in Excel for Mac

Page 2 of 2http://support.microsoft.com/kb/187667

Formula to count the number of words separated by a character in a cell

The following formula counts the number of words in a cell that are separated by a specific character:=IF(LEN(TRIM(<cell_ref>))=0,0,LEN(<cell_ref>)- LEN(SUBSTITUTE(<cell_ref>,<char>,""))+1)

where <cell_ref> is the cell reference and <char> is the character separating the words.

Note There are no spaces in the above formula; multiple lines are used only to fit the formula into this document. Do not include any spaces when you type it intothe cell. This formula does not need to be entered as an array formula.

Example 4: Counting the number of words separated by a space in a cell

Follow these steps to count the number of words in a cell where the words are separated by a space character:

1. Start Microsoft Excel and open a new workbook.2. Type the following on sheet1:

The formula in cell A2 returns a value of 4 to reflect that the string contains four words separated by spaces. If words are separated by multiple spaces or if wordsstart or end in a space it doesn't matter. The TRIM function removes extra space characters and starting and ending space characters in the text in the cell.

In Microsoft Excel, you can also use a macro to count the occurrences of a specific character in a cell, or range of cells. For additional information, click the followingarticle number to view the article in the Microsoft Knowledge Base:

89794 (http://support.microsoft.com/kb/89794/ ) How to use Visual Basic for Applications to count the occurrences of a character in a selection in Excel

 Article ID: 187667 - Last Review: October 6, 2011 - Revision: 4.0

APPLIES TO

Microsoft Excel 2004 for MacMicrosoft Excel X for MacMicrosoft Excel 98 for Macintosh

Keywords: kbhowto KB187667

A1: The car drove fast A2: =IF(LEN(TRIM(A1))=0,0,LEN(TRIM(A1))-LEN(SUBSTITUTE(A1," ",""))+1)

Properties