Excel COUNTIFS Function
The Excel COUNTIFS function returns the number of cells in a range that meet one or more specified criteria
Example: Excel COUNTIFS Function
=COUNTIFS(C10:C16,">500",C10:C16,"<1000")
|
Result in cell E10 (2) - returns the number of cells that are greater than 500 but less than 1000, from the same range (C10:C16).
|
=COUNTIFS(C10:C16,">500",B10:B16,"Apples")
|
Result in cell E11 (1) - returns the number of cells that are greater than 500 and apple as the product, associated with ranges (C10:C16) and (B10:B16), respectively.
|
=COUNTIFS(C10:C16,">"&C5,C10:C16,"<"&C6)
|
Result in cell E10 (2) - returns the number of cells that are greater than the value in cell (C5) but less than the value in cell (C6), from the same range (C10:C16).
|
=COUNTIFS(C10:C16,">"&C5,B10:B16,C7)
|
Result in cell E11 (1) - returns the number of cells that are greater than the value in cell (C5) and equal to the value in cell (C7), associated with ranges (C10:C16) and (B10:B16), respectively.
|
METHOD 3. Excel COUNTIFS function using the Excel built-in function library with hardcoded value
EXCEL
=COUNTIFS(C10:C16,">500",C10:C16,"<1000") Note: in this example we are populating COUNTIFS function input boxes that are associated with two criteria. |
METHOD 4. Excel COUNTIFS function using the Excel built-in function library with links
EXCEL
=COUNTIFS(C10:C16,">"&C5,C10:C16,"<"&C6) Note: in this example we are populating COUNTIFS function input boxes that are associated with two criteria. |
Dim ws As Worksheet
ws.Range("E10") = Application.WorksheetFunction.CountIfs(ws.Range("C10:C16"), ">500", ws.Range("C10:C16"), "<1000")
ws.Range("E11") = Application.WorksheetFunction.CountIfs(ws.Range("C10:C16"), ">500", ws.Range("B10:B16"), "Apples")
End Sub
Worksheets: The Worksheets object represents all of the worksheets in a workbook, excluding chart sheets.
Range: The Range object is a representation of a single cell or a range of cells in a worksheet.
Worksheet Name: Have a worksheet named COUNTIFS.
Data Range: Ensure that the data that you want to count from is captured in range ("C10:C16") and ("B10:B16") in the COUNTIFS worksheet.
Specific Value: Input the specific value that you want to test for in the VBA code by replacing 500, 1000 and Apples.
ADJUSTABLE PARAMETERS
Data Range: Select the range that you want to count from by changing the range ("C10:C16") and ("B10:B16") to any range in the worksheet that doesn't conflict with the formula.
Output Range: Select the output range by changing the cell references ("E10") and ("E11") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.
Dim ws As Worksheet
ws.Range("E10") = Application.WorksheetFunction.CountIfs(ws.Range("C10:C16"), ">" & ws.Range("C5"), ws.Range("C10:C16"), "<" & ws.Range("C6"))
ws.Range("E11") = Application.WorksheetFunction.CountIfs(ws.Range("C10:C16"), ">" & ws.Range("C5"), ws.Range("B10:B16"), ws.Range("C7"))
End Sub
Worksheets: The Worksheets object represents all of the worksheets in a workbook, excluding chart sheets.
Range: The Range object is a representation of a single cell or a range of cells in a worksheet.
Worksheet Name: Have a worksheet named COUNTIFS.
Data Range: Ensure that the data that you want to count from is captured in range ("C10:C16") and ("B10:B16") in the COUNTIFS worksheet.
Specific Value: Input the specific value that you want to test for in cell ("C5"), ("C6") and ("C7") in the COUNTIFS worksheet.
ADJUSTABLE PARAMETERS
Specific Value: Select the specific value that you want to test for by changing the value in cell ("C5"), ("C6") and ("C7").
Data Range: Select the range that you want to count from by changing the range ("C10:C16") and ("B10:B16") to any range in the worksheet that doesn't conflict with the formula.
Output Range: Select the output range by changing the cell references ("E10") and ("E11") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.
The Excel COUNTIFS function returns the number of cells in a range that meet one or more specified criteria.
=COUNTIFS(criteria_range1, criteria1, [criteria_rangle2], [criteria2], ...)
criteria_range1: (Required) The range of cells that you want to apply the criteria1 against.
criteria1: (Required) The criteria to be tested against criteria_range1.
criteria_range2: (Optional) The range of cells that you want to apply the criteria2 against.
criteria2: (Optional) The criteria to be tested against criteria_range2.
ADDITIONAL NOTES
Note 1: Excel allows up to 127 criteria_range and criteria arguments.