How to Automatically Sort Dataset in Google Sheets

how to automatically sort in google sheets 2

In this article, we will learn how to automatically sort in google sheets. Here we go with another new and exciting feature of google sheets.

Automatically sort can be done by using AppScript, we can write our logic and program our functions, and also automate them to run when a condition is satisfied. Automatically sort in google sheets simply means to sort the dataset automatically when a new entry is added, or a previous entry is updated, or an entry is deleted. The code will enable auto sorting after each change is made in our data, so we don’t need to sort our data again and again after changes, all we need to do is adding or changing the data and the data will automatically be sorted by a function running at the backend.

So, let’s get into it and make a basic auto sort function to sort a dataset automatically on edit. Before that, let’s go ahead with some important theoretical concepts.

Importance of automatic sorting in google sheets?

So, you are working with google sheets and maintaining large amount of data, you are using many varieties of sort function to manage and organize your data according to your need. But what is your data is varying, and your data is changing every hour and you are messing with sorting function again again and again. So, the one and only solution to this mess up is auto sort, don’t you know auto sort? I guess you don’t. So, let’s understand it to minimize your work load and avoid tedious work repeatedly. We need to learn it to save our time and make our work faster and accurate, every time.

Download/Copy Practice Workbook

How to Automatically Sort in Google Sheets

Code to Automatically Sort in Google Sheets

function dataSorting(){
  var ss = SpreadsheetApp.getActiveSpreadsheet()

//getting active spreadsheet
  var sheet = ss.getSheetByName("Sheet1")

//get sheet name to target the sheet from the spreadsheet
  var lastRow = sheet.getRange(2,1,sheet.getLastRow()-1,5)

//declaration of length of the function or from which row it will be executed.
  lastRow.sort({column:5,ascending: true});

//telling the column number and ascending true for sorting in ascending order
}

Assume, we have a dataset with Name, Age, City, Department and Tuition Fees columns. Now we want to sort the dataset using the Fee column automatically.

Here is the step by step process to sort this dataset automatically. This implies auto sort even after adding new rows of data.

Step 1

Open any data set with google sheets.

how to automatically sort in google sheets 0

 

Step 2

Go to extension in the main menu, and click on AppScript.

how to automatically sort in google sheets 2

Step 3

A code editor will open, now you need to put the auto sort code here.

See also  How to Sort Pivot Table in Google Sheets (Best Practice)

how to automatically sort in google sheets 3

Step 4

The code can be varied according to your columns and rows count. For now, just copy the code from above and paste in AppScript. Save the code by ctrl + s, and then click run.

how to automatically sort in google sheets 4

how to automatically sort in google sheets 4.1

how to automatically sort in google sheets 4.2

 

Step 5

Go to triggers, click on add trigger, go to select event type and select on edit and click on save. And you’re done.

how to automatically sort in google sheets 5

how to automatically sort in google sheets 5.1

how to automatically sort in google sheets 5.2

how to automatically sort in google sheets 5.3

 

how to automatically sort in google sheets 5.4

how to automatically sort in google sheets 5.5

how to automatically sort in google sheets 5.6

To recap, we learned how to automatically sort by in google sheets, it’s a unique and newly added feature in google docs and very helpful when we are dealing with the data that is frequently changed and updated. To code provided is for a basic function of auto sort you can play with it and make more complex functions according to your understanding, I will recommend you all to write this code by yourself it will give you better understanding to this code and help to write new functions of same type. Also, don’t forget to add trigger, otherwise the data will not sort automatically you will need to run code each time after making any change, so make sure you add and customize a trigger for your function.

Notes

Conclusion

In this article, we learned how to automatically sort in google sheets. This article is based on the code provided above; without code you cannot perform auto sort. So, it’s important to understand the code and try to make more functions to get use to of the functions. Avoid copying other’s code and start to write yours they are simple and easy you just need to understand it and write it by yourself to get familiar with. I hope you find this article helpful, please share with your social network and subscribe for more.

Content Protection by DMCA.com

M. Shaiq Ansari

Hi, I am Shaiq. A young and self-motivated content writer having years of experience expertise in MS Office suite, Google docs Editor Suite. I have a technical education background that empowers me to stand out in today's digital world. I am currently a freelance content creator and a part of a local digital marketing agency in Karachi Pakistan.

OfficeDemy.com
Logo
Enable registration in settings - general