A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Use an IF test around a counting formula.
If the goal is to count how many cells in B5:Q5 match the corresponding cells in B4:Q4, but return nothing when B5 is empty, use:
=IF(B5="","",SUM(IF(B5:Q5=B4:Q4,1,0)))
How it works:
-
IF(B5="","",...)checks whetherB5is empty. - If
B5is empty, the formula returns a blank. - If
B5is not empty,SUM(IF(B5:Q5=B4:Q4,1,0))counts the matching cells across the two ranges.
Important:
- This is an array formula in the documented
SUM+IFpattern. - Enter it by pressing Ctrl+Shift+Enter instead of just Enter. In Excel, that makes the formula evaluate the full range comparison.
If only a single condition is needed, COUNTIF is also available for counting cells that meet a criterion, but for comparing one range directly to another range, the SUM(IF(...)) pattern fits this case.