Google Sheets sort formula generator
Fill in your range and the columns to sort by, and get a formula for an empty cell. It makes a sorted copy of the table that updates by itself whenever the original changes. Pick plain SORT for several columns, SORT with ranges (Sheets' answer to Excel's SORTBY), QUERY with order by, SORTN to drop repeated rows, or a custom order such as High, Medium, Low. The formula is built in your browser; nothing you type here is sent anywhere. Checked against Google's Sheets function help on 1 November 2026.
={A1:F1; SORT(FILTER(A2:F, A2:A<>""), 1, TRUE)}
The numbers count columns from the start of the range (A = 1), TRUE = A to Z, FALSE = Z to A.
How to use it
Put this in an empty cell; it makes a sorted copy that updates by itself. A new tab works best (type the range with its tab name, like Data!A1:F). The copy needs empty cells to its right and below as wide and tall as the table; if something is in the way, Sheets shows #REF! with "Array result was not expanded". Do not put it inside the columns it reads, or it refers to itself.
Which formula to pick
- SORT (
=SORT(range, column, is_ascending, ...)): the column numbers count from the start of the range, so inB2:Fcolumn D is 3.TRUEis A to Z (smallest, oldest first),FALSEZ to A. Add more pairs to sort by multiple columns. - SORT with ranges: instead of a number, each sort column is a range with the same rows, like
C2:C. That lets you sort by a column you do not copy. Excel calls this SORTBY; Google Sheets has no SORTBY function, and SORT accepts ranges in its place. - QUERY order by (
=QUERY(range, "select * order by C desc, A asc", 1)): the last number is how many header rows the range has, so the header stays on top. Inside the quotes the letters are the sheet's column letters. Handy when you also wantwherefilters or only some columns (select A, C). - SORTN to drop duplicates (
=SORTN(range, 9^9, 2, column, is_ascending)):9^9means "all rows", and tie mode 2 removes duplicates (Google's help: "show at most the first n rows after removing duplicate rows"; rows count as repeats when their sort columns match), so a list with the same email twice keeps one row. - Custom order:
MATCH(C2:C, {"High";"Medium";"Low"}, 0)turns each value into its place in your list (1, 2, 3; case ignored) and SORT sorts by that number.IFERRORgives values that are not in the list a place after the last one, so they and blank cells end up at the bottom.
The catches
- The copy loses formatting and checkboxes. A formula returns values only: colours, number formats, checkboxes, notes and links stay in the original rows. Format the copy's columns yourself.
- The copy cannot be edited. Typing into it breaks the formula (
#REF!). People keep editing the original; the copy follows. - Blank cells. Rows whose sort cell is empty go to the bottom with SORT and SORTN; QUERY puts them first in A to Z order. "Skip empty rows" leaves out rows whose first column is blank (with QUERY it adds
where A is not null; if column A holds text and empty rows still show, change it towhere A <> ''). - Text that looks like a number or date sorts as text ("10" before "2"). Check with
=ISNUMBER(B2). - Separators. If your sheet's locale writes decimals with a comma (File > Settings), Sheets wants
;between arguments: switch the separator above. - The original stays unsorted. The formula only sorts the copy. To sort the rows themselves every time something changes, use the auto sort script generator (Apps Script) or the add-on below.
No code: KeepSorted
The add-on sorts the original in place without code: no second copy, so formatting, checkboxes and notes move with their rows and people keep editing the same table. Select the range, pick the sort columns, Save. Free: one area per tab, up to 2 sort columns, no trial clock. Pro ($5/month or $39/year): up to 5 sort columns, custom orders like High > Medium > Low, ticked checkbox rows to the bottom, stacked tables sorted separately, and sorting after form responses, other editors' changes and an hourly check.
KeepSorted is built and in testing. It is not in the Google Workspace Marketplace yet. Leave your email and we send one message when you can install it.
The generators and the formulas stay free either way.
More KeepSorted tools and guides
- Auto sort script generator (Apps Script that sorts the original)
- Auto-sort when a new row is added
- Auto-sort alphabetically (A to Z)
- Auto-sort by date, newest first (and Google Forms)
- Auto-sort by multiple columns when data changes
- StaySorted alternative: an honest comparison
Sources
- SORT function · SORTN function (tie modes) · QUERY function · Query language: order by
- FILTER · MATCH · Using arrays in Google Sheets (
{a; b}stacks rows)