Counting within a cell

G

Guest

Is there a formula which would allow you to count the number of characters
within a cell which match a certain criteria? FIND will tell you the first
instance of a character or group of characters. LEN will tell you the count
of all characters in a cell.

What I need is something like this:
FORMULA("Betty Crocker Fruit By The Foot Assorted Fruit Roll Fruit Snact 1ct
0.5oz", " ") = 12, because there are 12 spaces in the text.

Alternatively, is there some way to make FIND work backwards and instead of
telling you the first instance of a character, have it tell you the last
instance?

My problem is I am trying to get the "1ct" out of the above example, but the
character count and number of spaces varies with each cell.

Thanks for the advice,
Jane
 
B

Bob Phillips

=LEN(A1)-LEN(SUBSTITUTE(A1,"lookup_char",""))

will give you the number of lookup_char in cell A1.

To get the last instance of say a space, you use

=FIND("~",SUBSTITUTE(A1," ","~",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))

but you need this and the last but one to get your 1ct, so you use

=MID(A1,FIND("~",SUBSTITUTE(A1," ","~",LEN(A1)-LEN(SUBSTITUTE(A1,"
",""))-1))+1,FIND("~",SUBSTITUTE(A1," ","~",LEN(A1)-LEN(SUBSTITUTE(A1,"
",""))))-FIND("~",SUBSTITUTE(A1," ","~",LEN(A1)-LEN(SUBSTITUTE(A1,"
",""))-1)))

--

HTH

RP
(remove nothere from the email address if mailing direct)
 

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