# SORT formula generator

> Describe what you need and get a SORT formula for Excel and Google Sheets, run on real data before you copy it. Plus 8 tested SORT examples.

Source: https://spreadsheetpractice.com/tools/formula-generator/sort · Updated October 29, 2026 · Formulas and results on this page were run by the Spreadsheet Practice formula engine on November 20, 2026

SORT returns a sorted copy of a range, ordered by any column you choose, smallest to largest or the reverse.

Describe the task at [SORT formula generator](https://spreadsheetpractice.com/tools/formula-generator/sort) and get a SORT formula for Excel and Google Sheets, tested on real data.

## Tested SORT examples

### Sort data with a formula

`=SORT(A2:B7,2,-1)`

Excel. Result on the sample sheet: 6 rows (D2:E7). [See it and try it](https://spreadsheetpractice.com/formulas/sort-data-with-a-formula)

### Sort by two columns with a formula

`=SORT(A2:C9,{2,3},{1,-1})`

Excel. Result on the sample sheet: 8 rows (E2:G9). [See it and try it](https://spreadsheetpractice.com/formulas/sort-by-two-columns-with-a-formula)

### Fix the #SPILL! error

`=UNIQUE(B2:B8)`

Excel. Result on the sample sheet: 4 rows (E2:E5). [See it and try it](https://spreadsheetpractice.com/formulas/spill-error-blocked-range)

### Get a list of unique values

`=SORT(UNIQUE(B2:B10))`

Excel. Result on the sample sheet: 5 rows (D2:D6). [See it and try it](https://spreadsheetpractice.com/formulas/list-unique-values)

### Get unique values

`=SORT(UNIQUE(FILTER(B2:B,B2:B<>"")))`

Google Sheets. Result on the sample sheet: 5 rows (D2:D6). [See it and try it](https://spreadsheetpractice.com/formulas/unique-values-from-a-whole-column)

### Why are my dates not sorting correctly

`=SORTBY(A2:C8,DATEVALUE(A2:A8))`

Excel. Result on the sample sheet: 7 rows (E2:G8). [See it and try it](https://spreadsheetpractice.com/formulas/dates-not-sorting-correctly)

### Sort birthdays by month and day

`=SORTBY(A2:B9,MONTH(B2:B9),1,DAY(B2:B9),1)`

Excel. Result on the sample sheet: 8 rows (D2:E9). [See it and try it](https://spreadsheetpractice.com/formulas/sort-birthdays-by-month-and-day)

### Get the most recent entry for every customer

`=SORT(FILTER(A2:C11,B2:B11=MAXIFS(B2:B11,A2:A11,A2:A11)))`

Excel. Result on the sample sheet: 4 rows (E2:G5). [See it and try it](https://spreadsheetpractice.com/formulas/latest-entry-for-every-customer)

## Questions

### What does the SORT formula generator do?

You describe the task in plain English, and it writes the formula, using SORT where that's the right tool, for your table or a sample one. The formula is run in our engine in Excel and Google Sheets mode before you see it, so you get its result, not just a guess.

### What does SORT do?

SORT returns a sorted copy of a range, ordered by any column you choose, smallest to largest or the reverse.

### Can I learn to write SORT formulas myself?

Yes. Each example below opens a page where you try the formula in a live grid and it's checked as you go, and the SORT function page has a practice exercise.

---

Spreadsheet Practice (https://spreadsheetpractice.com) teaches spreadsheet formulas by practice: every exercise is graded in a live grid and re-checked on changed data.
