# SORTBY formula generator

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

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

SORTBY sorts one range by the values in another.

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

## Tested SORTBY examples

### Sort one column by another with a formula

`=SORTBY(A2:A9,B2:B9,-1)`

Excel. Result on the sample sheet: 8 rows (D2:D9). [See it and try it](https://spreadsheetpractice.com/formulas/sort-one-column-by-another-with-a-formula)

### Sort a list by another column

`=SORTBY(A2:A9,C2:C9,-1)`

Excel. Result on the sample sheet: 8 rows (E2:E9). [See it and try it](https://spreadsheetpractice.com/formulas/sort-a-list-by-another-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 by a custom order with a formula

`=SORTBY(A2:C10,XMATCH(B2:B10,F2:F4))`

Excel. Result on the sample sheet: 9 rows (H2:J10). [See it and try it](https://spreadsheetpractice.com/formulas/sort-by-a-custom-order)

### 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)

### Find the name of the second highest value

`=INDEX(SORTBY(A2:A9,B2:B9,-1),E1)`

Excel. Result on the sample sheet: Ben. [See it and try it](https://spreadsheetpractice.com/formulas/name-of-nth-highest-value)

## Questions

### What does the SORTBY formula generator do?

You describe the task in plain English, and it writes the formula, using SORTBY 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 SORTBY do?

SORTBY sorts one range by the values in another.

### Can I learn to write SORTBY 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 SORTBY 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.
