Auto Sort Google Sheets: Keep Rows in Order Automatically

How-to basics · Updated November 3, 2026

Auto Sort Google Sheets: Keep Rows in Order Automatically

To auto-sort a Google Sheets table, use SORT in a separate output area for a live sorted view, or add an Apps Script onEdit trigger to reorder the original rows after a user edits them. The built-in Data sorting commands rearrange rows when you choose them; they do not keep sorting automatically after later changes.

What auto sort means in Google Sheets

People use auto sort to mean two different things: sorting a table once, or having it maintain a chosen order as its data changes. Google Sheets supports both outcomes, but the methods differ. A menu sort changes the arrangement of the existing rows at that moment. A formula can show a live, sorted copy of the data. A script can move the original rows after edits.

Keeping entire records together is essential. If a task name is in column A, an owner in B, and a due date in C, sorting only column C would separate dates from their tasks and owners. Sort the whole data range, including every column that belongs to each record. Keep headings in a separate header row so they do not become mixed in with the records.

For many lists, a live sorted view is the simplest and safest kind of automation: people enter information in one table, while another area displays it in the desired order. If people need to edit rows directly in their current sorted positions, a script may be more appropriate, but it can be surprising when the row moves immediately after an edit.

Sort a table with Google Sheets menus

For a one-time sort, open the spreadsheet in a browser and select the complete table range, including all columns to keep together. Then choose Data > Sort range > Advanced range sorting options. Select Data has header row if the selection includes headings, choose the column to sort by, and select A to Z or Z to A. For dates and numbers, the same ascending and descending choices put earlier or smaller values first, or later or larger values first.

For example, if a project list occupies A1:D40 and row 1 contains headings, select A1:D40 and sort by the due-date column. Sorting only C2:C40 is not equivalent: it moves dates without moving their associated tasks. If the table is the main content of the sheet, Data > Sort sheet can sort the sheet by a selected column, but use it carefully when the sheet contains other information that should not move with the table.

Another option is Data > Create a filter. Use the filter button in a heading to sort the displayed table by that column. Filters also let you hide rows that do not meet selected criteria. When people want a personal sorting or filtering arrangement without changing what collaborators see, a filter view is often a better fit: open Data > Filter views and create a new view.

Use the SORT function for a live sorted view

The SORT function returns a sorted copy of a range. It does not rearrange the source rows, and the result updates when source values change. This makes it useful when an entry table should remain in the order people entered it but a report or dashboard needs a different order.

Suppose A2:D4 contains three task records, with task names in column A, owners in B, due dates in C, and status in D. If the dates are April 18, April 12, and April 15, respectively, enter this formula in an empty area outside A2:D4:

=SORT(A2:D4,3,TRUE)

The formula sorts by the third column of the selected range in ascending order. The resulting task order is the April 12 task, the April 15 task, and then the April 18 task, with each owner and status kept on its original task row. The result expands into neighboring cells, so leave enough empty space for all returned rows and columns. If existing values block the output, Sheets reports that the array result could not expand.

The number 3 means the third column within the range, not necessarily column C of the whole sheet. In a range starting at B2, for example, the third column of that range is D. TRUE means ascending; use FALSE for descending. A formula output is a view, not a second editable source table: make changes in the original data range.

Sort by more than one column

For records that need a primary and secondary order, add another sort-column and direction pair. With category in column A and task name in column B, this formula sorts the category first and task name second:

=SORT(A2:D40,1,TRUE,2,TRUE)

Here the formula assumes the complete records are in A2:D40. All records in the same category are arranged by task name, while categories themselves are arranged ascending. You can also choose descending order for either key by using FALSE for that key. The same idea works in the menu: use the advanced range sorting options to add another sort column after the first.

Make the primary key the value that should determine the broad grouping, such as region or status. Use the next key to order records inside each group, such as customer name or due date. This avoids repeatedly sorting one column at a time and accidentally losing a useful secondary order.

Can Sheets automatically resort the original table?

A standard menu sort does not keep running in the background. After someone changes a value, the row stays where it is until someone sorts again. A SORT formula recalculates its displayed result, but it leaves the source table in place. If the requirement is for edits to physically move rows in the original table, Google Sheets does not provide a simple built-in checkbox for that behavior; Apps Script is one way to implement it.

Automatic movement is not always desirable. Imagine editing the due date of a task while the list is sorted by due date. Once the edit is saved, the task may jump to another position, so the person editing can lose track of it. A sorted output view avoids that disruption. Consider whether users need to edit the sorted display or merely read it before choosing a method.

Use Apps Script to resort rows after edits

A bound Apps Script can sort a defined table after a user edits it. The example below assumes a sheet named Tasks, headings in row 1, and records in columns A:D, with the sort key in column C. It sorts all records by column C ascending when someone edits a cell in columns A:D. Change the sheet name, range width, and sort-column number to match the actual table.

function onEdit(e) {
  const sheet = e.range.getSheet();
  if (sheet.getName() !== 'Tasks') return;

  const firstDataRow = 2;
  const lastTableColumn = 4;
  const editFirstColumn = e.range.getColumn();
  const editLastColumn = e.range.getLastColumn();

  if (e.range.getLastRow() < firstDataRow) return;
  if (editFirstColumn > lastTableColumn || editLastColumn < 1) return;

  const lastRow = sheet.getLastRow();
  if (lastRow < firstDataRow) return;

  sheet.getRange(firstDataRow, 1, lastRow - firstDataRow + 1, lastTableColumn)
    .sort({column: 3, ascending: true});
}

To add it, open the spreadsheet, select Extensions > Apps Script, place the code in the project, and save. A function named onEdit is a simple trigger: it runs when a user edits the spreadsheet, without manually running the function. Test it on a copy first and confirm the range includes every column in each record. The example sorts the table after any edit in its columns, including edits to names or status, not only changes to the sort key.

Simple triggers have limits. They respond to direct user edits, not to a formula result changing on its own, and edits made by scripts or API requests do not fire a simple onEdit trigger. A script that sorts after every edit can also make a shared sheet feel jumpy. For more complex automation, such as a different rule for each tab or a scheduled process, the script needs more deliberate design and may require an installable trigger.

Choose the method that fits your sheet

  • Use a menu sort when you need to arrange the original table once, or occasionally refresh its order by hand.
  • Use a filter or filter view when people need to sort and narrow down a shared list while preserving useful views.
  • Use SORT when you want an always-updated display but prefer the original input rows to stay put.
  • Use Apps Script when edits must automatically rearrange the original table and the moving rows will not disrupt users.

For a simple task tracker, a good setup is often an entry tab with a stable order and a separate report area with a formula-sorted view. For a small personal list, using the sort menu again may be easier than maintaining a script. For a shared operational sheet, agree on the behavior with collaborators before automating movement: a row that changes position can affect how people refer to it during a conversation or review.

Common sorting problems and how to avoid them

If names, dates, or other values appear in an unexpected order, check whether the column contains mixed data types. A date stored as text may not sort like a real date, and numbers stored as text can behave differently from numeric values. Formatting a cell to look like a date does not necessarily convert text into a date value. Correct inconsistent entries in the source column before relying on a sort.

Also check for blank rows and missing values inside the table. A sort can move blank records, and a live formula that includes a much larger range than needed may display empty rows along with useful records. Use a range that fits the actual data, or carefully design a separate formula to exclude blanks if the table needs to grow. Avoid sorting an incomplete selection: if one record column is left out, the rows can become mismatched.

When a SORT formula shows an expansion error, inspect the cells to the right and below its output for existing content. Clear the obstruction or move the formula to an empty area. If a script does not run as expected, verify the sheet tab name, the header row, the column numbers, and whether the edit was made directly by a person. Formula recalculation and changes made by another automation do not behave like a direct edit trigger.

Frequently Asked Questions

Does Google Sheets have a built-in auto-sort setting?
No single setting continuously resorts a source table after every change. Use a SORT formula for a live sorted display, or Apps Script if edits should move rows in the original table.

How do I sort a Google Sheet alphabetically?
Select the whole table and use Data > Sort range > Advanced range sorting options. Choose the name column and A to Z, and indicate whether the selection has a header row.

Will a SORT formula change my original data?
No. It returns a sorted result in the cells where the formula is entered. Edit the original range to change the source; the displayed result updates from it.

Can a filter automatically sort new entries?
A filter provides sorting and filtering controls, but it is not the same as an on-edit rule that permanently moves every new record. For a continuously updated sorted display, use a formula or script suited to the workflow.

Can Apps Script sort only when the sort column changes?
Yes. The example can be adjusted to check whether the edited range intersects the sort-key column before sorting. That reduces unnecessary sorts, but multi-cell pastes and edits spanning several columns should be handled deliberately.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.