Count Multiple Instances of Text in a Cell

D

dave roth

Good Afternoon:

I need to be able to count multiple instances of the same piece of text in a
given cell, i.e. "blue, blue, red, green." How I currently have this setup
is:

=countif(I2:I44,"*blue*")
=countif(I2:I44,"*green*")
=countif(I2:I44,"*red*")
on separate rows. In the above example these will return 1 blue, 1 green,
and 1 red; I need it to return 2 blues.

Thanks very much, and a good weekend to all.

Dave Roth
 
T

T. Valko

Try this:

=(LEN(A12)-LEN(SUBSTITUTE(A12,"blue","")))/LEN("blue")

Note that SUBSTITUTE is case sensitive.

This version takes case into account:

=(LEN(A12)-LEN(SUBSTITUTE(UPPER(A12),"BLUE","")))/LEN("blue")
 
J

JE McGimpsey

One way (array-entered: CTRL-SHIFT-ENTER or CMD-RETURN):

=SUM(LEN(I2:I44)-LEN(SUBSTITUTE(I2:I44,"blue","")))/LEN("blue")
 
C

CLR

Oops, misread your post......they don't count multiple instances within a
single cell.

My Bad, sorry

Vaya con Dios,
Chuck, CABGx3
 
T

T. Valko

Ooops!

I see you're testing a range, not a single cell:

=SUMPRODUCT(LEN(I2:I44)-LEN(SUBSTITUTE(I2:I44,"blue","")))/LEN("blue")

=SUMPRODUCT(LEN(I2:I44)-LEN(SUBSTITUTE(UPPER(I2:I44),"BLUE","")))/LEN("blue")
 
D

Dave Peterson

And to avoid having to array enter the formula:
=SUMPRODUCT(LEN(I2:I44)-LEN(SUBSTITUTE(I2:I44,"blue","")))/LEN("blue")
 
D

dave roth

Thank you very much; that's exactly what I need.

JE McGimpsey said:
One way (array-entered: CTRL-SHIFT-ENTER or CMD-RETURN):

=SUM(LEN(I2:I44)-LEN(SUBSTITUTE(I2:I44,"blue","")))/LEN("blue")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top