# SORT Function

> Sort the values of a range or array with SORT in TX Sheet Control: sort index, ascending or descending order, sorting by column, spills and errors.

- **Product:** TX Sheet Control
- **Section:** Documentation
- **Kind:** Function
- **Path:** TX Sheet Control > API Reference > Formula Functions > SORT Function
- **217 words**
- **Web URL:** https://docs.textcontrol.com/tx-sheet-control/reference/formula-functions/sort/
- **LLMs URL:** https://docs.textcontrol.com/tx-sheet-control/reference/formula-functions/sort/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-sheet-control/reference/formula-functions/sort/llms-full.txt

---

Return the values of an array or range sorted. `sort_index` is the row or column to sort by (1 when omitted), `sort_order` is 1 for ascending (the default) or -1 for descending, and `by_col` TRUE sorts the columns instead of the rows. The sorted array spills into the neighboring cells. A `sort_index` outside the array or another `sort_order` returns `#VALUE!`.

### Syntax

```text
SORT(array, sort_index, sort_order, by_col)
```

Category: Lookup. Minimum arguments: 1. Maximum arguments: 4.

Available for supported offline calculation.

### Examples

```text
=SORT({3;1;2})
```

The formula spills 1, 2 and 3 into three rows.

Cell and range examples require appropriate input values in the referenced cells. Handle invalid arguments, formula errors and array and spill constraints.

### See Also

- [Formulas](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/formulas/llms-full.txt)
- [Custom Functions and Formula Data](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/custom-functions/llms-full.txt)

---

## Nearby

- **Previous:** [SMALL Function](https://docs.textcontrol.com/tx-sheet-control/reference/formula-functions/small/llms-full.txt)
- **Next:** [SORTBY Function](https://docs.textcontrol.com/tx-sheet-control/reference/formula-functions/sortby/llms-full.txt)
