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.
Table of Contents
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.
- To sort a data automatically every time a change is made.
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.
Step 2
Go to extension in the main menu, and click on AppScript.
Step 3
A code editor will open, now you need to put the auto sort code here.
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.
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.
Notes
- Write code by yourself for better understanding.
- Understand the code and try to make your unique function of similar type.
- Don’t forget to add a trigger to automatically call this function on any change.
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.