Counts the number of cells in multiple ranges that meet multiple criteria. More powerful than COUNTIF for complex conditional counting.
Master the fundamentals of Excel COUNTIFS function
COUNTIFS is the enhanced version of COUNTIF, supporting multiple AND conditions. It counts cells across multiple ranges where ALL specified criteria are met simultaneously. Perfect for complex filtering scenarios where you need to count data based on several conditions across different ranges.
Supports up to 127 criteria pairs
All criteria must be satisfied
Same operators as COUNTIF
All ranges must align
Function-specific parameters
Function-specific return type
Count by multiple dimensions
Count by segments
Count in date ranges
Complex conditional counts
Exact matching required
Returns numeric position
Handles missing text gracefully
=COUNTIFS(criteria_range1, criteria1, criteria_range2, criteria2, ...)First range to evaluate with criteria
First criterion to apply
Additional ranges and criteria (up to 127 pairs)
Count of cells meeting all criteria
Description: Counts cells meeting multiple criteria across ranges
Count with 2 conditions
Counts rows meeting both criteria
Simple VBA implementation
' Basic COUNTIFS in VBA
Sub COUNTIFSExample()
Dim result As Long
result = Application.WorksheetFunction.CountIfs(Range("A1:A100"), "North", _
Range("B1:B100"), 2023)
MsgBox "Count: " & result
End Sub
' Dynamic criteria
Sub CountByMultipleCriteria()
Dim ws As Worksheet
Set ws = ActiveSheet
Dim crit1Range As Range
Dim crit2Range As Range
Set crit1Range = ws.Range("Region")
Set crit2Range = ws.Range("Year")
ws.Range("Result").Value = Application.CountIfs(crit1Range, "North", _
crit2Range, 2023)
End Sub
' Complex report
Sub BuildComplexReport()
Dim ws As Worksheet
Set ws = ActiveSheet
Dim regions() As String
Dim i As Integer
regions = Array("North", "South", "East", "West")
For i = 0 To UBound(regions)
ws.Cells(i + 1, 1).Value = regions(i)
ws.Cells(i + 1, 2).Value = Application.CountIfs(ws.Range("Region"), regions(i), _
ws.Range("Year"), 2023)
Next i
End SubCount by segments
Count by multiple filters
Count by accounts and dates
Count by category and location
No cells meet all criteria
Ensure all criteria ranges same sizeSolution: Verify all criteria are met, check range alignment
Odd number of arguments
Always pair criteria_range with criteriaSolution: Criteria must come in pairs (range, criteria)
Different range sizes
Check range sizes matchSolution: All ranges must have same dimensions
Need ANY instead of ALL
SUM multiple COUNTIF resultsSolution: Use multiple COUNTIF formulas and add