Counting a specfic substring in a cell without counting another string that contains the same substring in that cell

dagda13

Board Regular
Joined
May 18, 2019
Messages
52
Hi,

I'm trying to do a count of specific substring in a range of cells. I've been able to count for substrings in a cell using the following formula:

=COUNTIF(A1:A3,"*fox*")

However, I'm running into trouble when the substring I'm counting for exists in the same cell in another string:
A
1 foxes
2 foxes, fox
3 fox, foxes

I'd like to get a hit only if the cell contains the substring "fox" on it's own, and not a string that contains the substring, ie., "foxes". For the above, the count should be 2, but I'm getting 5. Any idea how to go about this?

Thanks!
 
Last edited:

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Try

Book1
ABCD
1TextCriteriaResult
2foxesfox2
3foxes, fox
4fox, foxes
Plan1
Cell Formulas
RangeFormula
D2D2=SUMPRODUCT(--ISNUMBER(SEARCH(","&C2&",",","&SUBSTITUTE(A2:A4," ","")&",")))


Hope this helps

M.
 
Upvote 0
I got 3. Why did you get 5? My Excel counts "fox,foxes" as 1, not 2.

If you get 5, then use this formula:

=COUNTIF(A1:A3,"*fox*") - COUNTIF(A1:A3,"*foxe*")

Since I got 3, this formula gives 0 but if you get 5, then, 5-3 = 2, which is what you want.
 
Upvote 0
I got 3. Why did you get 5? My Excel counts "fox,foxes" as 1, not 2.

If you get 5, then use this formula:

=COUNTIF(A1:A3,"*fox*") - COUNTIF(A1:A3,"*foxe*")

Since I got 3, this formula gives 0 but if you get 5, then, 5-3 = 2, which is what you want.
Thanks very mucn, yky! This works too. :)
 
Upvote 0

Forum statistics

Threads
1,214,986
Messages
6,122,611
Members
449,090
Latest member
vivek chauhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top