Skip to Content

How do I sort only certain cells in google sheets?

Sorting data is an essential task when working with spreadsheets. Google Sheets makes it easy to sort your entire sheet alphabetically or numerically. But sometimes you only want to sort a portion of your data while keeping the rest intact. Whether you need to organize a few columns or sort a section without disturbing your header row, there are easy ways to selectively sort cells in Google Sheets.

Using Filter Views

One of the simplest ways to sort only some cells in Google Sheets is by using Filter Views. Here’s how:

  1. Select the cells you want to sort.
  2. Click the Filter icon in the toolbar.
  3. A drop-down menu will appear on each header cell. Click the drop-down and select Sort A-Z or Sort Z-A.

This will sort only the cells you selected while keeping the surrounding data in place. Filter views temporarily sort the visible cells without actually rearranging your spreadsheet.

Sorting with QUERY

The QUERY function lets you selectively sort cells based on criteria you specify. Here’s the basic syntax:

=QUERY(range, “select * order by Col1 [asc|desc], Col2 [asc|desc],…”

To sort column A ascending and column C descending while ignoring column B, you would use:

=QUERY(A1:C25,”select * order by A asc, C desc”)

Let’s look at a full example. Say we have a spreadsheet of products and sales data:

Product Sales Rep Units Sold
Widget John 500
Gadget Mary 200
Gizmo Mary 300

To sort the product names alphabetically while keeping the rows intact, we can use:

=QUERY(A1:C7,”select * order by A asc”)

The result would be:

Product Sales Rep Units Sold
Gadget Mary 200
Gizmo Mary 300
Widget John 500

The QUERY function is powerful for sorting specific columns while ignoring others.

Sort Ranges with Scripts

For more complex selective sorting, you can use Google Apps Script. Here is a script that allows you to define a sort range and will only sort those cells:

function sortRangeOnly(range, column, ascending) {

var sheet = range.getSheet();
var rangeValues = range.getValues();

// Sort the array
rangeValues.sort(function(a, b) {
if(ascending) {
return a[column] > b[column] ? 1 : -1;
} else {
return a[column] Sort Tables with Filters

Another way to selectively sort data is by using tables and filters. To do this:

1. Select your data and click Insert > Table.
2. In the table toolbar, click Filter.
3. An arrow will appear on each header. Click the arrow for the column you want to sort and select Sort A-Z or Sort Z-A.

This will only sort that column while keeping the table structure intact. The benefit of using tables is that filtering and sorting do not affect cells outside the table.

Sort Selected Columns with ARRAYFORMULA

For a quick way to sort multiple columns without sorting the entire sheet, you can use the ARRAYFORMULA function with some manipulation.

Here is a formula to sort columns A and C descending:

=ARRAYFORMULA(SORT(QUERY(A1:C25, “select A, C”), 2, 0))

Breaking this down:

– `QUERY` selects only the columns we want to sort (A and C)
– `SORT` then sorts those columns
– `ARRAYFORMULA` displays the sorted output

The end result is columns A and C will be sorted while column B remains static.


While Google Sheets doesn’t have a built-in way to sort only certain cells, there are several workarounds:

– Use Filter Views for quick temporary sorting
– Employ the QUERY function to sort specified columns
– Write scripts to precisely define a sort range
– Add tables and use the Filter feature
– Combine ARRAYFORMULA and other functions

The key is to selectively include the columns you want sorted while excluding those you want to remain static. With the right approach, you can organize subsets of data for improved analysis while maintaining your spreadsheet’s integrity.

Being able to selectively sort data in Google Sheets helps you draw insights from key columns without disrupting the rest of your worksheet. Whether you use visual filters, versatile functions, or customizable scripts, controlling which cells get sorted takes your spreadsheet skills to the next level.