The Google Sheets SORT function sorts the rows of a given range or array by the values in one or more columns. Its syntax is SORT(range, sort_column, is_ascending, [sort_column2], [is_ascending2]), and it returns a new sorted array without altering your original data.
What the SORT Function Does
SORT is a dynamic array function in Google Sheets. You type it into a single cell, and it automatically spills the sorted results into the cells below and to the right. Unlike the menu command Data > Sort sheet, SORT creates a separate output that updates live when your source data changes. This makes it ideal for building dashboards, ranking lists, or preparing data for other formulas.
The function works on any range—a block of cells, a single column, or even an array created by another formula like FILTER or QUERY. It sorts rows, not individual cells, so each row stays intact as it moves.
How the Syntax Works
Here is the breakdown of each argument:
- range – The data you want to sort. This can be a reference like
A2:C20or a formula that returns an array. - sort_column – The column within the range to sort by. This is specified as a number (1 = first column of the range, 2 = second, etc.), not a letter.
- is_ascending – Use
TRUEfor A→Z or smallest→largest,FALSEfor Z→A or largest→smallest. - sort_column2, is_ascending2 – Optional additional sort levels. You can add as many pairs as you need.
For example, with data in A2:C20 where column A is names and column B is sales, =SORT(A2:C20, 2, FALSE) returns all rows sorted by sales from highest to lowest. The original range remains untouched.
How to Choose the Right Sort Column
The sort column number is relative to the range you give, not the spreadsheet. If your range is B2:D20, column 1 is B, column 2 is C, and column 3 is D. A common mistake is typing a letter like “B” instead of 2—that will cause a #VALUE! error.
For multi-level sorting, list the primary sort first. Suppose you have a list of employees with department in column A and last name in column B, range A2:C20. To sort by department (A→Z) and then by last name (A→Z), use =SORT(A2:C20, 1, TRUE, 2, TRUE). The function applies the first pair as the main sort, then the second pair within ties.
Common Problems and Errors
Several issues trip up new users:
- #VALUE! error – Usually means the sort_column number is out of range (e.g., you used 4 for a 3-column range) or you typed a column letter.
- #REF! error – The output range overlaps the input range. SORT cannot write over its own source. Put the formula in a different column or sheet.
- #N/A error – The range contains mixed data types in the sort column (numbers and text). SORT treats text as larger than numbers, so check for stray text entries.
- Blank cells – Empty cells in the sort column are treated as the smallest values (when ascending) or largest (when descending). If that is not what you want, consider using
FILTERfirst to remove blanks.
Also, SORT is case-insensitive for text by default. “apple” and “Apple” sort together, with no guaranteed order between them.
SORT vs. Data Menu vs. QUERY
Google Sheets offers three main ways to sort, and they serve different purposes:
- SORT function – Dynamic, formula-based, leaves original data unchanged. Best for live reports and feeding other formulas.
- Data > Sort sheet / Sort range – Physically rearranges your data. Use when you want to permanently reorder the actual sheet, not create a separate view.
- QUERY with ORDER BY – More powerful for complex conditions, like sorting after filtering or joining data. Example:
=QUERY(A2:C20, "select * order by B desc")does the same as SORT but can combine with WHERE clauses.
For simple sorting, SORT is shorter and easier to read. For conditional sorting or when you need to aggregate, QUERY is often better.
Sorting with Other Functions
SORT pairs well with FILTER and UNIQUE. For instance, to get a unique list of products sorted alphabetically, use =SORT(UNIQUE(A2:A100)). To sort only rows that meet a condition, wrap FILTER inside SORT: =SORT(FILTER(A2:C20, B2:B20>100), 2, FALSE).
You can also use SORT with array literals. If you have two separate columns you want to combine and sort, try =SORT({A2:A10, B2:B10}, 1, TRUE). The curly braces create an array, and SORT treats it like a range.
Remember that SORT returns an array, so you cannot put it inside a cell that already has data below it. The spill range must be empty.
Frequently Asked Questions
Can I sort by a column not included in the output? No. The sort column must be part of the range you specify. If you want to sort by a hidden helper column, include it in the range and then use INDEX or CHOOSECOLS to select only the columns you want to display.
Does SORT work on merged cells? It can cause issues. Merged cells in the range can lead to unexpected results because SORT treats each cell individually. It is best to unmerge before sorting with a formula.
How do I sort by date? Dates in Google Sheets are numbers, so SORT works normally. Ensure the date cells are formatted as dates, not text. If they are text, convert them with DATEVALUE first.
Why does my SORT formula return a #SPILL! error? This happens when the output range is not empty. Clear the cells below and to the right of your formula, or move the formula to a new location.
Can I use SORT in Excel? Excel has a similar SORT function, but the syntax is different: SORT(array, [sort_index], [sort_order], [by_col]). It uses 1 for ascending and -1 for descending, and it requires Excel 365 or 2021. The Google Sheets version is not directly compatible.
Is there a way to sort by row instead of column? No, SORT always sorts rows. If you need to sort columns horizontally, you would have to transpose the data with TRANSPOSE, sort, then transpose back.
Related
- How Much Coding for Data Security?
- Google Sheets Query Sum: Formula & Examples
- Shortcut for Searching in Excel? Ctrl+F and More
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- How to Generate Random Numbers on a CalculatorGenerating a random number on a calculator is a handy trick for games, picking lottery-like numbers, sampling, or…
- Excel Named Ranges List: Find, View, and Manage Defined NamesTo see an Excel named ranges list, open Formulas > Name Manager in Excel for Microsoft 365 on…
- How to Add Clickable Checkboxes in Excel: Step by StepTo add a clickable checkbox in current Microsoft 365 for Windows, select the cell or cells where you…
- PowerShell Refresh Excel Power Query: How It WorksYes. On Windows, PowerShell can refresh Excel Power Query by automating the desktop Excel application through COM: open…
- Excel or Word for a Checklist? Compare the Best Fit for YouChoose Excel for a checklist you need to sort, filter, update, or track across many tasks; choose Word…
- County-Level Heat Map in Excel: How to Build OneYes—Microsoft Excel for Microsoft 365 can make a county-level heat map with a Filled Map chart. Prepare a…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.