COUNTIF is not working

Excel_VBA

New Member
Joined
Dec 19, 2009
Messages
42
I've got a very simple formula. It is =COUNTIF(A8,"dog") and it is returning a 0. Cell A8 contains "The dog is blue"

The COUNTIF cell and cell A8 are in general format. I tried changing the way the formula calculates from Automatic to Manual and back to Automatic again. Not working.

I'm using Excel 2007. Any ideas what is wrong?
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I've got a very simple formula. It is =COUNTIF(A8,"dog") and it is returning a 0. Cell A8 contains "The dog is blue"

The COUNTIF cell and cell A8 are in general format. I tried changing the way the formula calculates from Automatic to Manual and back to Automatic again. Not working.

I'm using Excel 2007. Any ideas what is wrong?
As written, your formula will only work if the cell contains only the word dog.

Try it like this:

=COUNTIF(A8,"*dog*")

The * asterisks are wildcards which has the meaning of "count if this cell contains the substring "dog" anywhere within the cell".
 
Upvote 0
=(len(a8)-len(substitute(upper(a8),"dog","")))/3

Edit: Do you want to count the occurences of dog in A8 or just return 1 if dog is in there somewhere?
 
Upvote 0
This returns a 1 if "dog" is present;
Code:
=IFERROR(COUNTIF(A8,"* dog *"),0)+IFERROR(COUNTIF(A8,"dog *"),0)+IFERROR(COUNTIF(A8,"*dog"),0)
But will not count an instance of dog as a substring (e.g dogtown won't count).
 
Last edited:
Upvote 0
This will count any instance of dog in the cell;
Code:
=IFERROR(COUNTIF(A8,"* dog *"),0)+IFERROR(COUNTIF(A8,"dog *"),0)+IFERROR(COUNTIF(A8,"*dog"),0)
But will not count an instance of dog as a substring (e.g dogtown won't count).

Mines a bit smaller ;)
 
Upvote 0
Thats really weird, all it's doing is comparing the size diff between the string and the Uppercase string with DOG replaced.
 
Upvote 0
Try it like this:

=COUNTIF(A8,"*dog*")

The * asterisks are wildcards which has the meaning of "count if this cell contains the substring "dog" anywhere within the cell".

It worked. I see the problem now. Thank you for your suggestion. Thank you to the others who also replied. You solutions may come in handy in the future. Now I'll be able to sleep better tonight.
 
Upvote 0
Thats really weird, all it's doing is comparing the size diff between the string and the Uppercase string with DOG replaced.
I think use of UPPER is the problem if "dog" is lower case it appears that UPPER("The blue dog") is evaluated as NOT containing the word "dog" so there is no substitution.
This works:
Code:
=(LEN(A8)-LEN(SUBSTITUTE(UPPER(A8),"DOG","")))/3
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,843
Members
452,948
Latest member
UsmanAli786

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