Sub topic 10
Keeping ranges the same size
This chapter assumes you can enter and copy formulas, know the difference between relative and absolute references, and have already written a basic SUMIFS, COUNTIFS, or AVERAGEIFS formula. It covers one rule that all three functions share: every range in the formula must have the same shape. It also covers what happens when that rule is broken in a way Excel does not report.
The rule
In a SUMIFS, COUNTIFS, or AVERAGEIFS formula, every range argument must have the same number of rows and the same number of columns. That includes the sum range (or average range) and every criteria range. Excel pairs the cells by position. The first cell of the sum range goes with the first cell of each criteria range, the second with the second, and so on.
The ranges do not need to sit side by side, in the same columns, or even on the same sheet. They only need to have the same shape.
The examples use the sales layout from earlier in the tutorial: headers in row 1, data in rows 2 to 100, with Date in A, Region in B, Product in C, Amount in D, and Notes in E.
=SUMIFS(D2:D100, B2:B100, "West")Here D2:D100 and B2:B100 both have 99 rows and 1 column. Row 2 of Amount is tested against row 2 of Region, row 3 against row 3, and so on down the list.
Case 1: different sizes give #VALUE!
If one range has a different size, the function returns #VALUE!. This formula is one row short on the criteria range:
=SUMIFS(D2:D100, B2:B99, "West")D2:D100 has 99 rows and B2:B99 has 98, so the result is #VALUE!. Excel does not guess which rows you meant.
The most common causes are:
- Typing one range by hand and getting an end row wrong.
- Including the header row in only one range, such as
D1:D100withB2:B100. - Adding data below the old last row, then extending only some of the ranges.
- Mixing a whole-column reference with a bounded one, such as
D:DwithB2:B100.
Whole-column references are fine when you use them for every range:
=SUMIFS(D:D, B:B, "West")Both ranges have 1,048,576 rows, so they match. Text in the header row does not matter here. The header "Amount" in D1 is ignored when summing, and the header "Region" in B1 does not equal "West". Whole-column ranges are slower on very large workbooks, but they remove the risk of one range ending early.
The error also applies to COUNTIFS and AVERAGEIFS:
=COUNTIFS(B2:B100, "West", C2:C99, "Laptop")This returns #VALUE! because the second pair is one row short.
Case 2: same size, wrong rows
A formula whose ranges are the same size but start on different rows gives no error. It pairs the wrong cells and returns a wrong number.
=SUMIFS(D2:D100, B1:B99, "West")Both ranges have 99 rows, so Excel accepts the formula. But the criteria range starts one row too high. With the sample data, the pairs become:
| Position | Criteria cell | Value tested | Sum cell | Amount |
|---|---|---|---|---|
| 1 | B1 | Region (header) | D2 | 1200 |
| 2 | B2 | West | D3 | 300 |
| 3 | B3 | East | D4 | 310 |
| 4 | B4 | West | D5 | 1150 |
The shifted formula adds 300 and 1150 and returns 1450. The correct answer is 1510, from the West rows 1200 and 310. Nothing in the cell tells you the result is wrong.
Check the ranges before you trust the formula
These habits catch both kinds of problem:
- Select the formula cell and press F2. Excel colors each range in the formula and outlines it on the sheet. Check that the colored outlines start and end on the same rows.
- Look at the row numbers in the formula text. The start row and end row should be identical across every range, such as
2and100in each. - Compare against a known answer. Filter the data to West, select the Amount column, and read the sum on the status bar. It should equal your SUMIFS result.
- Test with a count.
=COUNTIFS(B2:B100, "West")should equal the number of rows shown after you filter to West.
Ranges on other sheets and in two dimensions
The ranges do not have to be on the same sheet. This works if both ranges are 99 rows by 1 column:
=SUMIFS(Data!D2:D100, Regions!A2:A100, "West")Excel pairs the first row on Data with the first row on Regions. It does not check that those rows describe the same sale. Use this only when the two sheets are kept in the same order.
Ranges may also have more than one column, as long as every range has the same shape. This counts cells, not rows:
=COUNTIFS(B2:C100, "West", D2:E100, ">100")Both ranges are 99 rows by 2 columns. The cell at the top left of one range is paired with the top left of the other, B2 with D2, then C2 with E2, and so on. Two-column ranges work, but they are easy to misread. Most formulas are clearer with single-column ranges.
Ranges must also be one contiguous block. You cannot pass a union such as (B2:B50, B60:B100).
SUMIF behaves differently
The older single-condition function SUMIF does not enforce this rule. If its sum range is a different size from the criteria range, Excel resizes it. It starts at the top left cell of the sum range and uses the shape of the criteria range.
=SUMIF(B2:B100, "West", D2:D50)This does not give an error. Excel treats the sum range as D2:D100. If you switch from SUMIF to SUMIFS, formulas that worked before can return #VALUE!. The cause is that the sum range was never the right size, and SUMIF was hiding it.
Keeping ranges aligned as the data grows
Fixed ranges such as 2:100 become wrong when data goes beyond row 100. Inserting rows inside the range extends every range together. Typing new data below row 100 extends none of them. Three approaches reduce the risk:
- Use whole-column references for every range. This is simple, and the size is always the same.
- Convert the data to an Excel table and use structured references such as
Sales[Amount]andSales[Region]. All columns of a table always have the same number of rows, so a mismatch cannot happen. - Use generous fixed ranges, such as rows 2 to 5000, for every range. This works but leaves a hidden limit.
=SUMIFS(Sales[Amount], Sales[Region], "West")Summary of symptoms
| Symptom | Likely cause | Fix |
|---|---|---|
| `#VALUE!` | One range has a different number of rows or columns | Make every range start and end on the same rows |
| `#VALUE!` after mixing `D:D` with `B2:B100` | Whole-column and bounded ranges mixed | Use whole columns for all ranges or bounded for all |
| Total is slightly off, no error | Ranges are the same size but start on different rows | Align the start and end rows, then compare with a filtered total |
| Total ignores new rows | Ranges end above the new data | Use a table or whole-column references |
Exercise
A colleague writes =COUNTIFS(B2:B100, "West", C1:C99, "Laptop") for the sales sheet. Does it return an error? If not, why is the result still unreliable, and how would you fix it?
Show answer
It does not return an error, because both ranges have 99 rows. The second range starts on row 1, so each Region cell is tested against the Product from the row above. The header "Product" is paired with the first Region value, and every other row is shifted by one. The count is wrong without any warning. Fix it by changing the second range to C2:C100 so both ranges cover rows 2 to 100, or use whole-column references or Sales[Region] and Sales[Product] in a table.
Exercise
=SUMIFS(D2:D100, B2:B100, "West", A2:A99, ">=" & DATE(2025,1,1)) returns #VALUE!. What is wrong?
Show answer
The date range A2:A99 has 98 rows while the other two ranges have 99. Change it to A2:A100 so all three ranges have the same shape.