Excel COUNTIF Function for Two Conditions

This short Excel tip shows how to use Excel's COUNTIF function to count the number of data points between two values. Listed below are the various conditions, and the corresponding formulas using the COUNTIF function. The trick is simply to subtract one condition from the other.

To download a sample spreadsheet containing these COUNTIF formulas using some made-up data, click here: countif-example.xls. This example shows how the formulas can be made a little more dynamic, by concatenating the conditional operator (<, <=, >, >=, <>) with a cell reference.

The data for the following formulas would be contained in column A.
Condition Formula
1 < x < 4 =COUNTIF(A:A,"<4")-COUNTIF(A:A,"<=1")
1 <= x < 4 =COUNTIF(A:A,"<4")-COUNTIF(A:A,"<1")
1 < x <= 4 =COUNTIF(A:A,"<=4")-COUNTIF(A:A,"<=1")
1 <= x <= 4 =COUNTIF(A:A,"<=4")-COUNTIF(A:A,"<1")

REFERENCES:

Another Method:
   MrExcel.com, "Excel CountIf or Sumif with two conditions" http://www.mrexcel.com/td0128.html


CITE THIS PAGE AS:

Wittwer, J.W., "Excel COUNTIF Formulas for Two Conditions" From Vertex42.com, Janurary 15, 2005, http://www.vertex42.com/ExcelTips/excel-countif-function.html


Excel Templates

Vertex42 Articles