
Third parties use cookies for their purposes of displaying and measuring personalised ads, generating audience insights, and developing and improving products. This includes using first- and third-party cookies, which store or access standard device information such as a unique identifier. If you agree, we’ll also use cookies to complement your shopping experience across the Amazon stores as described in our Cookie Notice. We also use these cookies to understand how customers use our services (for example, by measuring site visits) so we can make improvements. In Excel, you can also use a macro to count the occurrences of a specific character in a cell, or range of cells.We use cookies and similar tools that are necessary to enable you to make purchases, to enhance your shopping experiences and to provide our services, as detailed in our Cookie Notice. The TRIM function removes extra space characters and starting and ending space characters in the text of the cell. If words are separated by multiple spaces or if words start or end in a space, it does not matter.

The formula in cell A2 returns a value of 4 to reflect that the string contains four words separated by spaces. To count the number of words in a cell where the words are separated by a space character, follow these steps: Example 4: Counting the Number of Words Separated by a Space in a Cell This formula does not need to be entered as an array formula. Do not include any spaces when you type it into the cell. There are no spaces in the above formula multiple lines are used only to fit the formula into this document. Where cell_ref is the cell reference, and "a" is replaced by the character you want to count. The value of cell A8 is 4 because the text "apple" appears four times in the range.įormula to Count the Number of Occurrences of a Single Character in One Cell Start Excel, and then open a new workbook.Ī8: =SUM(LEN(A2:A7)-LEN(SUBSTITUTE(A2:A7,"apple","")))/LEN("apple")

Example 1: Counting the Number of Occurrences of a Text String in a Range This formula can replace all later formulas in this article except the formula to count the number of words in a cell. 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. To enter a formula as an array in Excel for Macintosh, press COMMAND+RETURN. To enter a formula as an array in Excel for Windows, press CTRL+SHIFT+ENTER.

The above formula must be entered as an array formula.
