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.

Intermediate 20 min read

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

ABC
1NameDeptSalary
2LauraFinance52000
3OmarSales47500
4SofiaIT61200
5TomSales44800
6MeiIT58300
7JonasFinance49900

A staff list in A1:C7.

How spilling works

  1. Click E2 and type =SORT(A2:C7, 3, -1) (sort by the 3rd column, descending).
  2. Press Enter. Six rows and three columns of results appear in E2:G7. Only E2 contains a formula.
  3. Click F4. The formula bar shows the formula greyed out: the cell is part of the spill range, outlined in blue.
  4. Change Sofia's salary in C4 to 45,000. The sorted list rearranges itself immediately.
E2fx=SORT(A2:C7, 3, -1)
ABCDEFG
1NameDeptSalary
2LauraFinance52000SofiaIT61200
3OmarSales47500MeiIT58300
4SofiaIT61200LauraFinance52000
5TomSales44800JonasFinance49900
6MeiIT58300OmarSales47500
7JonasFinance49900TomSales44800

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*2 in 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

Formula
FILTER(array, include, [if_empty])
E2fx=FILTER(A2:C7, B2:B7="Sales")
ABCDEFG
1NameDeptSalary
2LauraFinance52000OmarSales47500
3OmarSales47500TomSales44800
4SofiaIT61200
5TomSales44800
6MeiIT58300
7JonasFinance49900

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 in H1 gives 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:

Formula
=SORTBY(A2:C7, B2:B7, 1, C2:C7, -1)
Department A→Z, then salary high→low within each department.

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:

F2fx=SUMIFS(C2:C7, B2:B7, E2#)
EF
1DeptTotal salary
2Finance101900
3IT119500
4Sales92300

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 as mmm yyyy).
  • =SEQUENCE(4, 7, DATE(2026,3,2)) gives a four-week calendar grid starting Monday 2 March.

More array helpers in Microsoft 365

FunctionExampleDoes
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
Note. Dynamic arrays and FILTER, SORT, SORTBY, UNIQUE, SEQUENCE and RANDARRAY are available in Microsoft 365, Excel 2021 and later, Excel for the web and current Excel for Mac. TAKE, DROP, CHOOSECOLS, VSTACK and HSTACK arrived later and need Microsoft 365 or Excel 2024. In Excel 2019 and older, a spilling formula opened from a newer file appears as a legacy array formula {=...} 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'.

Tip. Spill ranges work beautifully as the source for charts and drop-downs that should grow by themselves. Create a name that refers to =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?

2. Which formula lists the staff in Sales OR IT?

3. What does E2# refer to?

4. What does FILTER return when no rows match and the if_empty argument is missing?

5. Which formula returns the numbers 1 to 12 in a row?

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 17 KB