I have a spreadsheet that has a column of cells where each cell contains a single word. I would like to count the occurrences of some words. I can use the COUNTIF function for most words, but if the word is "true" or "false", I get 0.
A B
1 apples 2
2 true 0
3 false 0
4 oranges 1
5 apples
In the above spreadsheet table, I have these formulas in cells B1, B2, B3 and B4:
=COUNTIF(A1:A5,"apples")
=COUNTIF(A1:A5,"true")
=COUNTIF(A1:A5,"false")
=COUNTIF(A1:A5,"oranges)
As you can see, I can count apples and oranges, but not true or false. I have also tried this:
=COUNTIF(A1:A5,TRUE)
But that does not work either.
Note -- I am using Excel 2007.
Resolution:
It appears that Excel treats "true/TRUE" and "false/FALSE" as magic strings when they appear in formulas -- they are treated as functions: TRUE() and FALSE() instead of strings.
If you need to count true and false in a column, you will not get a count if you use "true" or "=true" as the criteria. There are some approaches you can use to count true and false as words.
Use a pair of COUNTIF functions. Either of the following works:
=COUNTIF(A1:A5,"*true")-COUNTIF(A1:A5,"*?true")or
=COUNTIF(A1:A5,"<truf")-COUNTIF(A1:A5,"<=trud")Create a new column with true converted to "T" and false converted to "F" using the formula:
=IF(A1="true","T",IF(A1="false","F",""))Then trues and falses can be counted using:
=COUNTIF(A1:A5,"T") =COUNTIF(A1:A5,"F")Don't use "true" and "false" to begin with, use something else (such as T and F).
Thanks to Sux2Lose for the wildcard idea and Martin Smith for the idea to use comparisons with the strings immediately greater and less than true or false.