# How to sort one column by another with a formula in Excel

Use SORTBY: =SORTBY(A2:A9,B2:B9,-1) returns the names in A ordered by the values in B, largest first. The sort column does not have to be in the output.

**Excel:** `=SORTBY(A2:A9,B2:B9,-1)` (Excel 2021, 2024 and Microsoft 365)

**Google Sheets:** Google Sheets has no SORTBY. Use `=SORT(A2:A9,B2:B9,FALSE)`, which sorts by another column the same way.

## Example

Sample data (row 1 is the header):

| A | B | C | D |
| --- | --- | --- | --- |
| Rep | Sales |  | Ranked reps |
| Priya | 48200 |  |  |
| Tom | 61500 |  |  |
| Ines | 39800 |  |  |
| Marcus | 72300 |  |  |
| Hana | 55100 |  |  |
| Owen | 44700 |  |  |
| Lars | 67400 |  |  |
| Aiko | 52900 |  |  |

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

Result (spills 8 × 1): Marcus; Lars; Tom; Hana; Aiko; Priya; Owen; Ines

## How it works

`SORTBY(array, by_array, order)` orders the first range by the values in the second. Order `-1` is descending, `1` ascending. Unlike SORT, the sorting column does not have to be part of the result, and you can add more sort keys.

The result spills down from the cell you type in, so leave the cells below empty.

## Other ways

- `=INDEX(A2:A9,MATCH(LARGE(B2:B9,SEQUENCE(8)),B2:B9,0))`: Works without SORTBY, but breaks on tied values. (Repeats a name when two reps have the same sales.)

## Common mistakes

- A #SPILL! error means something is in the way of the results. Clear the cells below.
- The two ranges must be the same height.

## Questions

**How do I sort by two columns?**

Add another pair: `=SORTBY(A2:C9,B2:B9,1,C2:C9,-1)`.

Every formula and result on this page was checked by running it in the Spreadsheet Practice formula engine on 2026-11-20.

Source: https://spreadsheetpractice.com/formulas/sort-one-column-by-another-with-a-formula
