Sub topic 2
Formulas that work on whole ranges
This chapter assumes you can enter and edit formulas, use relative and absolute references, and use basic functions such as SUM and IF. You need Excel for Microsoft 365 or Excel 2021 or later.
Ranges as arrays
An array is a rectangular block of values. In Excel, a range such as B2:B6 is an array of five values. The dynamic array calculation engine, which Excel 2021 and Microsoft 365 use, treats a range as that whole block. It no longer reduces the range to a single cell first.
This changes what an ordinary operator does. If you apply *, + or > to a range, Excel applies it to every value in the range. It returns one result for each value.
Array arithmetic in a worked example
Suppose a sales sheet holds quantities in B2:B6 and unit prices in C2:C6. Before dynamic arrays, you wrote =B2*C2 in row 2 and filled it down. Now you can enter this once, in D2:
=B2:B6*C2:C6Excel multiplies the ranges item by item. The first quantity is multiplied by the first price, the second by the second, and so on. The formula returns five values, and they fill D2:D6 with no fill-down.
You can wrap the operation in a function. To get the total revenue in one cell, write:
=SUM(B2:B6*C2:C6)The multiplication produces an array of five line totals, and SUM adds them. No helper column is needed.
How the shapes must match
Excel pairs values by position, so the shapes of the arrays matter.
| Left operand | Right operand | Result |
|---|---|---|
| 5 rows by 1 column | 5 rows by 1 column | 5 rows by 1 column, item by item |
| 5 rows by 1 column | A single value | 5 rows by 1 column, the value is reused |
| 5 rows by 1 column | 1 row by 4 columns | 5 rows by 4 columns, every pairing |
| 5 rows by 1 column | 3 rows by 1 column | 5 rows, with `#N/A` where no partner exists |
The third row is useful. A column and a row combine into a grid. For example, a column of prices times a row of tax rates gives a price for every rate.
The last row is a common error. When two ranges have the same orientation but different lengths, the extra positions in the longer range get #N/A. Check that the ranges you combine are the same size.
Functions that expect one value
Many functions used to take a single value in an argument. When you give them a range, they now work on every item and return an array. This formula tests every cell in C2:C6:
=IF(C2:C6>100,"High","Low")It returns five labels, one for each price. The comparison C2:C6>100 produces five TRUE or FALSE values, and IF chooses a label for each.
Common errors
- Mismatched sizes. Ranges with unequal lengths give
#N/Ain the unmatched positions. - Text in numeric arithmetic. If one cell holds text such as
"n/a", the item that uses it returns#VALUE!. The other items still calculate. - Using
ANDorORfor item-by-item tests. These functions collapse an array to one TRUE or FALSE. To test every item, multiply the conditions for AND, or add them for OR:
=IF((B2:B6>10)*(C2:C6>100),"Both","Not both")Exercise
Column B holds quantities in B2:B6 and column C holds prices in C2:C6. Write one formula, entered in a single cell, that returns the total revenue. Then say what result you get if C2:C6 is replaced with C2:C5.
Show answer
Use =SUM(B2:B6*C2:C6). If the price range is C2:C5, the ranges differ in length. The fifth position has no partner, so it returns #N/A, and SUM then returns #N/A as well.