Excel Auto Sort by Value: How to Set It Up
- Average speed
- km/h
- Result
- Finish time
- 50 min
- You entered
- Distance
- 10 km
- You entered
Excel does not have a single button that makes a range permanently auto-sort itself as you type, but you can achieve automatic sorting by value using a few built-in features: a dynamic array formula (SORT), a Table with a sort state, or a short VBA macro. This article explains each method, when to use it, and the common pitfalls, so you can pick the one that fits your workflow.
Formula
The SORT function is the simplest way to auto-sort a range by value. Its syntax is:
=SORT(array, [sort_index], [sort_order], [by_col])
- array – the range of cells to sort (required).
- sort_index – the column number within array to sort by (default 1).
- sort_order – 1 for ascending (A to Z, smallest to largest), -1 for descending (default 1).
- by_col – FALSE (default) sorts by row, TRUE sorts by column. Rarely needed.
The result is a dynamic array that spills into adjacent cells. If you change a value in the source range, the sorted output updates instantly.
Worked Example
Suppose you have a list of product names in A2:A6 and their prices in B2:B6. You want the list sorted by price, lowest to highest, in columns D and E.
- In D2, enter:
=SORT(A2:B6, 2, 1) - Press Enter. Excel spills the sorted array into D2:E6.
- Change B4 from 15 to 5. The output re-sorts automatically.
If your data is only one column, say numbers in A2:A10, use =SORT(A2:A10) to get them sorted ascending.
When to Use Each Method
Choose the method based on whether you need a live, formula-driven sort or a one-time sort that stays fixed.
- SORT function – best for data you update often and want a separate sorted view. It requires Excel 365 or Excel 2021 (dynamic arrays).
- Table + sort – convert your range to a Table (Ctrl+T), then apply a sort. New rows added to the table are included in the sort when you re-apply it, but the sort is not automatic on entry.
- VBA macro – a Worksheet_Change event can re-sort a range every time a cell changes. Works in all Excel versions, but requires enabling macros and a bit of code.
How to Create a Table That Sorts Automatically
Tables don’t auto-sort as you type, but they make re-sorting easy and include new data.
- Select your data range (with headers).
- Press Ctrl+T and confirm “My table has headers�.
- Click the drop-down arrow in the header of the column you want to sort by.
- Choose “Sort A to Z� or “Sort Z to A�.
- When you add a new row, the table expands. To re-sort, click the header drop-down again and re-apply the sort.
This is a manual step, but it’s faster than re-sorting a normal range because the table range is dynamic.
VBA Macro for True Auto-Sort
If you want the sort to happen the moment you change a value, a small macro is the only built-in way (besides the SORT function). Here’s a simple approach:
- Press Alt+F11 to open the VBA editor.
- In the Project Explorer, double-click the sheet you want (e.g., Sheet1).
- Paste this code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Set rng = Range("A1:B10") ' adjust to your range
If Not Intersect(Target, rng) Is Nothing Then
Application.EnableEvents = False
rng.Sort Key1:=Range("B1"), Order1:=xlAscending, Header:=xlYes
Application.EnableEvents = True
End If
End Sub
- Close the editor and save as a macro-enabled workbook (.xlsm).
Now any change in A1:B10 triggers a sort by column B. Be careful: this re-sorts the whole range, so it may reorder rows you were editing. Also, undo won’t work after the macro runs.
Common Problems and Misconceptions
Many users expect Excel to sort automatically like a database, but it doesn’t by default. Here are the typical issues:
- “My SORT formula shows #SPILL!� – The output range isn’t empty. Clear cells below the formula or move it.
- “The sort doesn’t include new rows.� – With a normal range, you must update the range in the formula or use a Table. With a Table, the SORT function can reference the whole column (e.g.,
=SORT(Table1)). - “Sorting by value also moves the row, but I only want to sort one column.� – Sorting a single column independently will misalign your data. Always sort the entire range that belongs together.
- “My numbers sort as text (1, 10, 2).� – This happens when the cells are formatted as text. Convert them to numbers by selecting the column, clicking the warning icon, and choosing “Convert to Number�.
Alternatives: Power Query and Excel Online
If you need a more robust auto-sort that refreshes with a click, Power Query (Get & Transform) can sort and load a table, but it doesn’t update in real time—you must refresh. In Excel for the web, the SORT function works the same as in desktop, but VBA is not supported. For a truly live sort without formulas, consider using a PivotTable (it sorts by default) or a separate sheet with the SORT function.
Frequently Asked Questions
Can I make Excel auto-sort a column as I type without VBA?
Yes, use the SORT function in a separate area. It updates instantly when you change a value in the source range. It’s the closest to “auto-sort� without macros.
Why does my SORT formula stop working when I add a row?
Because the range reference in the formula is static. Either expand the range manually, or convert your data to a Table and use =SORT(Table1) so it includes new rows automatically.
Does sorting a table mess up my formulas that reference cells?
If your formulas reference specific cells (like =A1), sorting can break them. Use structured references (like =Table1[Column1]) or avoid sorting data that other formulas depend on by absolute cell references.
Is there a way to auto-sort in Google Sheets?
Yes, Google Sheets has a SORT function too, and also a built-in “Create a filter� that can sort, but it’s not automatic. The SORT function works the same way as Excel’s.
Can I auto-sort by multiple columns?
Yes, use the SORT function with multiple sort_index and sort_order arguments, or use the Sort dialog (Data > Sort) to add levels. For example, =SORT(A2:C10, {2,3}, {1,-1}) sorts by column 2 ascending, then column 3 descending.
Related
Formula used
in t | Finish time | min | 50 | 0 in d | Distance | km | 10 | 0 out pace | Average pace | min/km | t / d | 2 out speed | Average speed | km/h | d / (t / 60) | 2
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.