Can I use COUNTIF on two columns to compare values?

Shalom's Arrayformula solution is really good, but I could not make it work with AND function embedded into IF, so I had to find another solution, and finally I have found it!

=ROWS(FILTER(A1:B4, A1:A4 > B1:B4))

This solves the original problem in the question. On the other hand, you can use multiple conditions, use the filtered range itself in other functions, if necessary.

(This is a Google Sheet solution, havn't tried it in Excel)


Actually this is something I would do with a program.

Create a macro to:

  • insert column C.
  • set range("cN").value to "=bN-aN" for all N where range("aN").value <> "".
  • do your countif calculation and shove it into a cell (not column C).
  • delete column C.

There may be an easier non-programming way but I don't know it (and then your question would be closed anyhow).


This can be done using Excel array formulas. Try doing something like this:

=SUM(IF(A1:A5 > B1:B5, 1, 0))

The very very important part, is to press CTRL-SHIFT-ENTER instead of just ENTER when you finished inputting the formula. Otherwise it won't understand you want to treat the data as an array.