Excel COUNTIFS: Step-by-Step Guide
In this article
COUNTIFS counts the rows in a range that meet every condition you give it. The syntax is =COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2], …). Each range must be the same size, and each pair adds an AND condition: a row counts only if it matches all of them. For a single condition, COUNTIF is enough; use COUNTIFS when you need two or more.
What You'll Need
- Excel 2016 or later, Microsoft 365, or Excel for the web. COUNTIFS is also available in Excel 2007 and later.
- A worksheet with data laid out in columns, ideally with a header row.
- Criteria values (text, numbers, dates, or cell references) that you can type or point to.
Step-by-Step
- Set up your data. Put each field in its own column and keep one header row. For example: A1 Region, B1 Product, C1 Units, D1 Date. Avoid blank rows inside the data and avoid merged cells in the columns you will count.
- Pick a cell for the result. Click an empty cell outside the data, such as F2. This is where the count will appear.
- Start the formula. Type
=COUNTIFS(. Excel will show the argument names as you go. You can type them or use the mouse to select ranges. - Enter the first range and its criteria. Select the first column you want to test, then type a comma, then the value to match. Example:
=COUNTIFS(A2:A100, "North". Text criteria go in double quotes; numbers can be typed without quotes. - Add the second range and criteria. Type a comma, select the next column, comma, then the value. Example:
=COUNTIFS(A2:A100, "North", B2:B100, "Widget". Each range must start and end on the same rows as the first range. - Close the formula and press Enter. Add the closing parenthesis:
=COUNTIFS(A2:A100, "North", B2:B100, "Widget"). The cell shows the number of rows where both conditions are true. - Use cell references for flexible criteria. Put the criteria in cells, for example H1 = North and H2 = Widget, then write
=COUNTIFS(A2:A100, H1, B2:B100, H2). Change H1 or H2 and the count updates without editing the formula. - Add more conditions if needed. Continue the pattern: range, comma, criteria, comma. COUNTIFS accepts up to 127 range/criteria pairs. Example with three:
=COUNTIFS(A2:A100, H1, B2:B100, H2, C2:C100, ">10"). - Use operators for numbers and dates. Wrap the operator and value in quotes:
">10","<=100","<>"for not blank,">="&DATE(2024,1,1)for dates on or after 1 January 2024. To combine an operator with a cell reference, use">"&H3. - Use wildcards for text.
"*Widget*"matches any text containing Widget;"?"matches a single character. Wildcards work with text, not with numbers. - Copy the formula down or across. If you plan to fill the formula, lock the ranges with absolute references:
$A$2:$A$100. Press F4 after selecting a range to add the dollar signs. Without them, copied formulas shift and count the wrong rows. - Check the result. Compare the count with a quick filter: select the data, use Data > Filter, set the same conditions, and see how many rows remain. The numbers should match.
Common Mistakes
- Ranges of different sizes. If the first range is A2:A100 and the second is B2:B99, Excel returns a #VALUE! error or an unexpected result. All ranges must cover the same number of rows.
- Forgetting quotes around text.
COUNTIFS(A2:A100, North)fails because North is treated as a name. Use"North". - Putting the operator outside the quotes.
>10typed directly is not valid; write">10". - Mismatched data types. Numbers stored as text will not match numeric criteria. Check with ISNUMBER or convert the column.
- Extra spaces. "North " and "North" are different. Trim the data or use wildcards carefully.
- Relative ranges when filling. Copying a formula without $ shifts the ranges and produces wrong counts.
- Using COUNTIFS for OR logic. COUNTIFS is AND-only. For OR, add two COUNTIFS results or use SUMPRODUCT.
Tips
- Use whole-column references like A:A only when the sheet is small; they are slower on large workbooks.
- Keep criteria in visible cells so others can see and change them.
- Name your ranges (Formulas > Define Name) to make formulas easier to read.
- Use
"<>"to count non-blank cells and""to count blanks. - For dates, remember Excel stores them as numbers; a date criterion without quotes may not behave as expected.
- Test one condition at a time, then add the next, to isolate errors.
Troubleshooting
#VALUE! error. The most common cause is ranges of different sizes. Select each range in the formula bar and confirm they cover the same rows. Also check that you have not left out a comma or a closing parenthesis.
Count is 0 when you expect more. Check for leading or trailing spaces, numbers stored as text, and criteria that do not match exactly. Test with a wildcard like "*North*" to see if spacing is the issue. Confirm the ranges point to the correct columns.
Count is too high. You may have included blank rows or the header row in the range. Start ranges at row 2, not row 1, unless the header is intended to match.
Formula worked, then broke after copying. Relative references shifted. Replace them with absolute references using $ or named ranges.
Dates not counting. Ensure the date column is a real date, not text. Use DATE() inside the criteria to avoid regional format problems, for example ">="&DATE(2024,1,1).
Wildcards not working. Wildcards apply to text criteria only. For numbers, use operators. Also check that the workbook is not set to treat wildcards literally in options.
Frequently Asked Questions
What is the difference between COUNTIF and COUNTIFS?
COUNTIF handles one range and one criterion. COUNTIFS handles multiple range/criterion pairs and counts only rows that meet all of them.
Can COUNTIFS use OR logic?
Not directly. Add separate COUNTIFS formulas together, or use SUMPRODUCT with Boolean arrays. Each COUNTIFS adds an AND condition.
How do I count between two numbers?
Use two conditions on the same range: =COUNTIFS(C2:C100, ">=10", C2:C100, "<=20"). Both criteria apply to the same column.
Can I use COUNTIFS across multiple sheets?
Yes, but each range must be on a single sheet. Reference each sheet separately, for example Sheet1!A2:A100. 3D references across sheets are not supported by COUNTIFS.
Why does COUNTIFS return a different number than a filter?
Filters may hide rows or apply text matching differently. Check that the filter uses the same exact criteria and that hidden rows are not excluded from the COUNTIFS range.
Does COUNTIFS work in Excel for the web and Google Sheets?
Yes, COUNTIFS is available in Excel for the web and in Google Sheets with the same syntax. Menu labels can differ slightly by version, device, or region.