Sub topic 10
Keeping ranges the same size
This chapter assumes you can enter and copy formulas, understand relative and absolute references, and have used SUM, COUNT, and AVERAGE on data with headers. It uses the sample sales layout, with data in rows 2 to 100.
The rule
Every range in a SUMIFS, COUNTIFS, or AVERAGEIFS formula must have the same number of rows and the same number of columns. Excel pairs the cells by position. The third cell of the criteria range is checked, and if it passes, the third cell of the sum range is added. If the ranges differ in size, there is nothing to pair.
=SUMIFS(D2:D100, B2:B100, "West")Both ranges here cover 99 rows, so row 2 lines up with row 2, row 3 with row 3, and so on.
The ranges do not have to be next to each other or start in the same column. They only have to match in shape.
What happens when they do not match
If the sizes differ, Excel returns #VALUE!. It does not guess or trim the longer range.
=SUMIFS(D2:D100, B2:B99, "West")This formula fails because the sum range has 99 rows and the criteria range has 98.
=COUNTIFS(B2:B100, "West", C2:C50, "Laptop")COUNTIFS has no sum range, but the same rule applies. Every range in every pair must match every other range.
A quieter mistake: ranges the same size but shifted
A worse problem is a formula that returns a number with no error. If both ranges are the same size but start on different rows, the rows are misaligned.
=SUMIFS(D3:D101, B2:B100, "West")Both ranges have 99 rows, so Excel accepts the formula. But the amount in row 3 is tested against the region in row 2. Every pairing is off by one row, and the total is wrong without any warning.
How misalignment usually happens
- You insert or delete rows in only part of the data, or edit one range by hand.
- You copy a formula down or across and a relative range moves, while the other ranges are locked with
$. - You select one range by clicking, and another by typing, and the endpoints differ by one row.
- You include a header in one range, such as
D1:D100, and skip it in another.
Locking all data ranges the same way avoids the copy problem:
=SUMIFS($D$2:$D$100, $B$2:$B$100, "West")If your data is an Excel table, structured references always cover the same rows, so mismatches cannot occur.
=SUMIFS(Sales[Amount], Sales[Region], "West")A quick check
Select each range in the formula and look at the row count shown in the bottom-right of the Excel window, or click in the formula bar and see the highlighted regions. All highlighted blocks should begin and end on the same rows.
Exercise
A formula =SUMIFS(D2:D100, B2:B100, "West", C2:C99, "Laptop") returns #VALUE!. What is wrong, and how do you fix it? Then explain why =SUMIFS(D2:D100, B3:B101, "West") is worse, even though it returns a number.
Show answer
The second criteria range, C2:C99, has 98 rows while the others have 99, so the sizes differ. Change it to C2:C100. The second formula has equal sizes but the criteria range is shifted down one row, so each region is checked against the wrong amount. Excel shows no error, so the wrong total goes unnoticed.