Excel course · Lesson 21 of 34
Dynamic arrays: spill, FILTER, SORT, UNIQUE, SEQUENCE and #
Write one formula that returns many results: how spilling works, #SPILL! errors, FILTER, SORT, SORTBY, UNIQUE, SEQUENCE, TAKE and the # spill operator.
In Microsoft 365 and Excel 2021, a single formula can return a whole list of results. Type =SORT(A2:C7) in one cell and the sorted table appears across as many cells as it needs. This behaviour is called spilling, and the functions designed for it are the dynamic array functions. They replace many tasks that used to need PivotTables, Advanced Filter, helper columns or Ctrl+Shift+Enter array formulas.
The data
| A | B | C | |
|---|---|---|---|
| 1 | Name | Dept | Salary |
| 2 | Laura | Finance | 52000 |
| 3 | Omar | Sales | 47500 |
| 4 | Sofia | IT | 61200 |
| 5 | Tom | Sales | 44800 |
| 6 | Mei | IT | 58300 |
| 7 | Jonas | Finance | 49900 |
A staff list in A1:C7.
How spilling works
- Click
E2and type=SORT(A2:C7, 3, -1)(sort by the 3rd column, descending). - Press Enter. Six rows and three columns of results appear in
E2:G7. OnlyE2contains a formula. - Click
F4. The formula bar shows the formula greyed out: the cell is part of the spill range, outlined in blue. - Change Sofia's salary in
C4to 45,000. The sorted list rearranges itself immediately.
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Name | Dept | Salary | ||||
| 2 | Laura | Finance | 52000 | Sofia | IT | 61200 | |
| 3 | Omar | Sales | 47500 | Mei | IT | 58300 | |
| 4 | Sofia | IT | 61200 | Laura | Finance | 52000 | |
| 5 | Tom | Sales | 44800 | Jonas | Finance | 49900 | |
| 6 | Mei | IT | 58300 | Omar | Sales | 47500 | |
| 7 | Jonas | Finance | 49900 | Tom | Sales | 44800 |
One formula, eighteen results, sorted by salary from high to low.
You cannot edit or delete individual cells in a spill range; edit or delete the formula in its first cell instead. If the source grows, for example when it is an Excel table, the spill range grows too.
#SPILL! and how to fix it
If any cell where results need to go is not empty, the formula shows #SPILL! instead of overwriting your data. Click the warning icon next to the cell and choose Select Obstructing Cells to find the culprit.
- Something is in the way: a value, a space or even an empty string in the spill area. Clear it.
- Inside an Excel table: spilling formulas are not allowed in tables. Move the formula outside the table.
- Merged cells in the spill area: unmerge them.
- Spill range too big: a formula over whole columns, such as
=A:A*2in row 2, would spill past the bottom of the sheet. Use exact ranges or table columns. - Volatile size: a formula whose result size changes at every recalculation, such as
=SEQUENCE(RANDBETWEEN(1,100)); Excel shows#SPILL!with the reason 'Spill range size is unknown'.
FILTER
FILTER(array, include, [if_empty])| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Name | Dept | Salary | ||||
| 2 | Laura | Finance | 52000 | Omar | Sales | 47500 | |
| 3 | Omar | Sales | 47500 | Tom | Sales | 44800 | |
| 4 | Sofia | IT | 61200 | ||||
| 5 | Tom | Sales | 44800 | ||||
| 6 | Mei | IT | 58300 | ||||
| 7 | Jonas | Finance | 49900 |
Every row where Dept is Sales.
- AND: multiply conditions.
=FILTER(A2:C7, (B2:B7="IT")*(C2:C7>60000))returns Sofia only. - OR: add conditions.
=FILTER(A2:C7, (B2:B7="IT")+(B2:B7="Finance"))returns four people. - Nothing found: without the third argument FILTER returns
#CALC!. Add a message:=FILTER(A2:C7, B2:B7="HR", "No staff"). - Criteria from a cell:
=FILTER(A2:C7, B2:B7=H1)with a drop-down inH1gives an instant report (Data validation: drop-down lists and dependent lists).
SORT and SORTBY
SORT sorts by column position: =SORT(array, [sort_index], [sort_order], [by_col]). SORTBY sorts by one or more other ranges, which is easier to read and survives column changes:
=SORTBY(A2:C7, B2:B7, 1, C2:C7, -1)Functions nest naturally: =SORT(FILTER(A2:C7, B2:B7="Sales"), 3, -1) lists the Sales team by salary.
UNIQUE
UNIQUE returns each distinct value once. =UNIQUE(B2:B7) returns Finance, Sales, IT (in order of first appearance); wrap it in SORT for alphabetical order. The optional third argument TRUE returns only values that appear exactly once, and =ROWS(UNIQUE(B2:B7)) counts distinct departments: 3.
The # spill reference operator
To refer to a whole spill range, put # after its first cell. E2# always means all the results that E2 currently spills, however many there are. This is how you build live summary tables:
| E | F | |
|---|---|---|
| 1 | Dept | Total salary |
| 2 | Finance | 101900 |
| 3 | IT | 119500 |
| 4 | Sales | 92300 |
E2 =SORT(UNIQUE(B2:B7)). F2 =SUMIFS(C2:C7,B2:B7,E2#) spills one total per department.
Add a new department to the source and both columns extend automatically. The # operator also works in charts' named ranges, data validation sources (=$E$2#) and other formulas such as =COUNTA(E2#).
SEQUENCE
SEQUENCE generates numbers: =SEQUENCE(rows, [columns], [start], [step]).
=SEQUENCE(5)returns 1 to 5 down a column.=SEQUENCE(1, 12)returns 1 to 12 across a row, ready to be month numbers.=SEQUENCE(10, 1, 100, -10)counts down from 100 to 10.=EDATE(DATE(2026,1,1), SEQUENCE(12, 1, 0))returns the first day of every month of 2026 (format asmmm yyyy).=SEQUENCE(4, 7, DATE(2026,3,2))gives a four-week calendar grid starting Monday 2 March.
More array helpers in Microsoft 365
| Function | Example | Does |
|---|---|---|
| TAKE | =TAKE(SORT(A2:C7,3,-1), 3) | Top 3 earners: Sofia, Mei, Laura |
| DROP | =DROP(A1:C7, 1) | Removes the header row |
| CHOOSECOLS | =CHOOSECOLS(A2:C7, 1, 3) | Only Name and Salary |
| VSTACK | =VSTACK(Jan!A2:C50, Feb!A2:C50) | Appends lists from several sheets |
| HSTACK | =HSTACK(A2:A7, C2:C7) | Puts ranges side by side |
| XLOOKUP | =XLOOKUP(E2#, A2:A7, C2:C7) | Looks up every value in a spill range |
{=...} or shows #NAME?.The @ sign in old formulas
When a workbook created in an older version is opened in Microsoft 365, you may see an @ inserted in some formulas, such as =@A2:A10. This is the implicit intersection operator: it tells Excel to behave as it used to, returning a single value instead of spilling. You can usually leave it alone. In your own new formulas you rarely need it, but [@Column] in tables is the same idea: 'the value from this row'.
=Sheet1!$E$2# and use that name in the chart series or data validation list.Check yourself
1. A formula returns #SPILL!. What is the most common cause?
Clear the obstructing cells and the results spill.
2. Which formula lists the staff in Sales OR IT?
Adding conditions creates OR; multiplying creates AND.
3. What does E2# refer to?
The # spill operator refers to every cell the formula in E2 spills into.
4. What does FILTER return when no rows match and the if_empty argument is missing?
An empty result produces #CALC!; supply if_empty to show a message.
5. Which formula returns the numbers 1 to 12 in a row?
SEQUENCE(rows, columns): one row and twelve columns.