Auto Sort By Date

Learn how to automatically sort tasks by date in Google Sheets using Google Apps Script. This tutorial covers setting up triggers to keep your tasks organized without manual intervention.

I have a bunch of tasks and I want to sort them by date, but not just sorting by date, by going up to the A column, clicking here and sorting the sheet by Z to a . I want to do this automatically without clicking at all. So let's add new task. And if we add a date here, we want this to be at the top. Or at least sorted, right? Wherever it should be. So let's go to Extensions app script . We need to know one thing. We need to know the name of the sheet. It's called tasks. And we also need to know which column our dates are in that we wanna sort . Which is in the A column or one super simple function . We're gonna do spreadsheet app, get active spreadsheet with parentheses, get sheet by name with the name of the sheet tasks sort .

And now what do we sort the first column, number one, we have one more thing we can add here, which is comma true. That comma true means that it's ascending false for descending from highest to lowest, but we want lowest to highest when we're dealing with dates. So we save this or click on that save project to drive. We can click run and go here and we can see that our task is actually sorted correctly. But we wanna do this automatically. So let's go over to the left side. Triggers go over to the bottom right, add trigger . Choose which function to run. It's called my function . If we can cancel this, go back and rename it to sort by date Save. Go back to triggers, click add trigger on the bottom right now. Choose which function to run. We have the name sort by date.

We have select event source. Time driven. We need to do not. Spreadsheet . Now, here's where we can choose whatever automatic we want. We can do it every day. We can do it every minute. We can do it every hour. I'm gonna choose our for right now. Click save now 24 times a day. This sheet is gonna be sorted without me having to touch the sheet. I don't have to click run. I don't have to open app script . It's just gonna happen every hour. That's awesome, right? Auto sort by date. However, do you wanna do it every time you edit the sheet? Let's do that. Click add trigger , choose to function to run sort by date. Now we say event source is from spreadsheet. We click on event type. Click on edit, click save. We may have to authorize it at that time too.

Now, every time we edit a cell, add. Another new task? Is it sorted? Probably, but let's see if we need this at the very top. Let's say we should have done this in September, and there it goes. It's at the top. One more time. Say it's December 5th. September 5th. There it goes. It's automatically, every single time we edit anything on the sheet, edit a cell, delete a cell, delete the content in the cell, add more contents to the cell. Change a date if we're like, oh, that should have been in January next year. There it is now sorted automatically. Isn't that awesome? Hope you enjoyed that one. You are watching better sheets here on YouTube. Make sure you check out this video or this video and subscribe right

now to get more tips, tricks, how tos, get more out of your Google sheets than you ever have before. I'm excited to be making a ton more videos here. Ask me questions down in the comments and I will answer them in future videos. But for right now, right here, one of these videos is gonna be your next Google sheet.