Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Google Sheets Sort Range By Column


Sort Range By Column

Google sheet lets you sort data in a range by columns

It is possible to sort data in a sheet by range.

Note: To sort a range that has more than one column, the whole range of data has to be selected. Sorting just one can breaks the relationship between columns.

This is shown in an example later in this chapter.

The sort commands can be found in the Data menu.


Example (Sort Text)

Sort the Pokemon in the range A2:A21 by their Name, ascending from smallest to largest (A-Z).

Copy the values to follow along.

Copy Values
  1. Select the range A2:A21

Note: A1 is not included as it is the header for the column. This is the row that is dedicated to the filter. Including it will blend it with the rest.

  1. Click on the Data menu and select Sort range by column A, A → Z

This is the result:

Try again, this time with Sort range by column A, Z → A to see what that looks like!



Example (Sort Numbers)

Sort the Pokemon ascending by their Total stats from smallest to largest.

Copy the values to follow along.

Copy Values
  1. Select the range A2:A21

  1. Click on the Data menu and select Sort range by column A, A → Z

This is the result:

Great! The Pokemon were successfully sorted by their Total stats from smallest to largest. The sort commands work for both text and numbers.


A Non-Working Example (Sorting One Column In A Range)

This example shows how sorting column by range can break the relationship between multiple data columns.

In this example we have two columns with related data. Column A is the Pokemon Names and Column B is their Total stats. Try sorting just one of the columns (A2:A21) ascending by their Names.

Copy the values to follow along.

Copy Values
  1. Select the range A2:A21

  1. Click on the Data menu and select Sort range by column A, A → Z

This is the result:

The image above shows that the relationship between column A and B is broken. The Pokemon now have wrong Total stats.


Sorting More Than One Column

Select the whole range when sorting ranges with more than one column.

When sorting multiple columns, the sorting is done based on the column with cell having the blue rectangle. This is the cell that you start selecting your range with.

In the image below the sorting is done based on the Name values in column A

In the image below the sorting is done based on the Total stats values in column B

Example

This example shows how to sort data without losing the relationship between the data columns.

Sort the Pokemon based on their names in ascending order.

Copy the values to follow along.

Copy Values
  1. Select the range A2:B21

  1. Click on the Data menu and select Sort range by column A, A → Z

This is the result:

By selecting range A2:B21 the sort is done correctly, keeping the relationship between the data (Column A and B).

Now try to sort Pokemon based on their total stats in a descending order.



×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.