Reputation: 389
I have some cells with text. I need to count the occurrences of a specific word (not a list) from those cells.
Example sheet:https://docs.google.com/spreadsheets/d/1WECDbepLtZNwNfUmjxfKlCbLJgjyUBB72yvWDMzDBB0/edit?usp=sharing
So far I found one way to count it in English by using SUBSTITUTE to replace all these words with "":
=(LEN(B1)-LEN(SUBSTITUTE(UPPER(B1),UPPER(A5),"")))/LEN(A5)
However, I don't know why but it doesn't work in German.
Edited: I don't want to count "Hero" in "Heroes". However, I'd like to count "afk" in "AFK-Spiel" (German for example). Is it possible?
Upvotes: 3
Views: 8673
Reputation: 765
=COUNTIF(SPLIT(JOIN(" ", B1:B3), " -."&CHAR(10)), "Hero")
Where:
B1:B3
: cells with text "Hero"
: the word to countExplaination
JOIN(" ", B1:B3)
: Concatenation of all cells with textSPLIT(..., " -."&CHAR(10))
: Create an array with each wordsCOUNTIF(..., "Hero")
: Count each array item equals to "Hero"Example
if input text is:
Hero Hero-666 heroes heroic
➔ then formula will return 2.
=COUNTA(SPLIT(UPPER(JOIN(" ",B1:B3)), "HERO", false, false))-1
Where:
B1:B3
: cells with text "HERO"
: the string to countExplaination
JOIN(" ", B1:B3)
: Concatenation of all cells with textUPPER(...)
: Convert text in upper caseSPLIT(..., "HERO")
: Split on each occurences of the stringCOUNTA(...)-1
: Count how many splits have been doneExample
if input text is:
Hero Hero-666 heroes heroic
➔ then formula will return 4.
Upvotes: 7
Reputation: 10573
In your sheet you mention that the count should be 14.
Considering that, I believe you are looking for a solution to also include words like heroes
or Hero
If you want to include variations of hero
, like Hero
or Heroes
you can use the following:
Case insensitive for any language formula:
=COUNTIF(SPLIT(CONCATENATE(B1:B3), " "), "*heRO*")
You can even have *heRO*
placed in a cell like A7
and use
=COUNTIF(SPLIT(CONCATENATE(B1:B3), " "), A7)
If you want just the word Hero
, remove the asterisks *
around it.
It also works for any language (including German).
Upvotes: 1
Reputation: 1
try:
=ARRAYFORMULA(COUNTA(IFERROR(SPLIT(QUERY(SUBSTITUTE(
UPPER(B1:B3), UPPER(A5), "♦"),,99^99), "♦")))-1)
and for german:
=ARRAYFORMULA(COUNTA(IFERROR(SPLIT(QUERY(SUBSTITUTE(
UPPER(C1:C3), "HELD", "♦"),,99^99), "♦")))-1)
Upvotes: 0