10
2
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.
1Jay, this old question popped up again because of a new post. Embedding an answer in the question sort of messes with the intended structure of the site. Can you move the answer portion to an answer? – fixer1234 – 2015-05-01T20:32:25.287
3For what it's worth I've changed my mind on this. I guess Excel formulae could be considered a kind of declarative programming language. I don't think it is Turing complete without the use of VBA but then neither are regular expressions - which are deemed acceptable by the SO community! – Martin Smith – 2010-05-10T10:19:40.237
1Stick with the wildcard solution.
=COUNTIF(A1:A5,"<truf")-COUNTIF(A1:A5,"<=trud")
counts every string that begins with “true” or “trud”, such as “trudge”. – Scott – 2013-05-29T23:26:08.197