Count text instances in a group of cells?

I'm converting an Excel document. I used an array in Excel to count the number of times a certain word of text appeared in a group of cells. The array does not work in Numbers. How do I do this in Numbers?

iMac, OS X El Capitan (10.11.4)

Posted on Apr 11, 2016 10:29 AM

Reply
9 replies

Apr 11, 2016 12:35 PM in response to Bruce Kieffer

Hi Bruce,


COUNTIF should do the job for you. Here are two examples.

In the first, each cell in the group contains a single word.

User uploaded file

Formula in B2 of the smaller table, and filled dow the column:


B2: =COUNTIF(Words :: $A:$C,A)


The second contains the same words, embedded in text strings of varying lengths. Although I've included a space before and after the word in each example, the space is not necessary to the operatin of the formula.

User uploaded file

B2: =COUNTIF(Words in strings :: $A:$C,"*"&A&"*")


Fill down to end of column B.

The * is a wild card character meaning "any number of characters, including 'none'."


The total in the footer row at the end of each small table is a checksum to show me that all 27 words had been counted.


This method will count the number of cells containing the target word, but will not count multiple occurrences of the target word in a single cell. Cells containing more than one of the target words will be counted separately for each of the target words.

In the example below, where the entry in the single cell containing "avenue" has been edited to also contain "crescent" and "lane" (and to contain no spaces separating the words. Note the increases in counts for crescent and lane and in the total.


User uploaded file


Regards,

Barry

Apr 11, 2016 1:31 PM in response to Bruce Kieffer

Just in case you are working on something that requires counting multiple occurrence of a target word in the same cell, one approach is like this:


User uploaded file


The formula in B2, filled right and down, is:


=(LEN($A2)−LEN(SUBSTITUTE($A2,B$1,"")))÷LEN(B$1)


This takes the length of the original string, subtracts from it the length after all instances of the target word are removed, and divides that by the length of the target word. The result is the number of times the target word appeared in that cell. Do that for each cell and sum at the bottom.


If you don't have to many cells you are checking for counts then you can make the solution more compact with something like this in B2, filled right:


User uploaded file



Chances are you won't get as compact as the Excel array formula, but would still love to see it.


SG

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Count text instances in a group of cells?

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