You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Counting Every Occurrence of a Word in Multiple Cells

I need to count every occurrence of a word across multiple cells, preferably an entire column. So far I have been able to use countif, but this will only count the number of cells in the column that contain at least one occurrence of the word, which yields less than desirable accuracy for my project. In my use case, the word may be repeated multiple times per cell across multiple cells within the column. I need to count the total number of occurrences, not just the total number of cells that contain at least one occurrence.

Posted on Jan 20, 2022 3:08 PM

Reply
Question marked as Top-ranking reply

Posted on Jan 20, 2022 3:35 PM

One way to achieve this would be to create a new column that would count the number of occurrences of a word in a cell and sum up that column.


For instance if A1 is the word to search, column B is the source of your data and column C is the count of words for column B:


A1 = "blah"

B1 = "And he said blah blah blah"; C1 = COUNTMATCHES(B1, $A$1), thus C1 returns 3

B2 = "And he only said blah"; C2 = COUNTMATCHES(B2, $A$1), thus C2 returns 1

B3 = "And he said hello"; C3 = COUNTMATCHES(B3, $A$1), thus C3 returns 0


Then you use the SUM() function on column C to sum up all occurrences of this word which, in this example, would return 4.


4 replies
Question marked as Top-ranking reply

Jan 20, 2022 3:35 PM in response to geekforgreek

One way to achieve this would be to create a new column that would count the number of occurrences of a word in a cell and sum up that column.


For instance if A1 is the word to search, column B is the source of your data and column C is the count of words for column B:


A1 = "blah"

B1 = "And he said blah blah blah"; C1 = COUNTMATCHES(B1, $A$1), thus C1 returns 3

B2 = "And he only said blah"; C2 = COUNTMATCHES(B2, $A$1), thus C2 returns 1

B3 = "And he said hello"; C3 = COUNTMATCHES(B3, $A$1), thus C3 returns 0


Then you use the SUM() function on column C to sum up all occurrences of this word which, in this example, would return 4.


Jan 20, 2022 4:14 PM in response to 6x6

Tried out this new (to me) function, with the intention of fitting the the calculations in 6x6's example into a single formula.


Successful, but that success also revealed a weakness in the function when chosen for this task.


Like many functions, COUNTMATCHES does not differentiate between a 'word' and 'a string of letters containing the ordered set of letters in that word.'


Doesn't negate the usefulness of COUNTMATCHES, but does remind us that there are issues that may result in an over-count, or, if the count target is redefined, an undercount, missing words that are in the sample, but are not preceded by characters added to the word to avoid doggerel while including the plural, and possessive forms.


Regards,

Barry

Counting Every Occurrence of a Word in Multiple Cells

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.