Auto Sort By Last Edited Date

Learn how to automatically sort your Google Sheets by the last edited date using a simple app script. This tutorial covers creating timestamps and sorting functions to enhance your spreadsheet automation.

So you wanna auto sort by last edited date. Let's do this automatically, but we gotta write a little app script . Don't be scared. It's so little and so much fun. In a previous video I showed you how to edit by date. I showed you how to edit by priority. We had a little trick there. Go check out that video. But for last edited date, we need to do two things. We need to get the last edited date, which we can add a little timestamp here super quick. And then we need to actually also sort , so let's go up to extensions app script . And these were the last two functions that we had before we had sort by date and sort priority. I'm actually going to delete those and start over. We're gonna create a function called sort. By date. We're gonna put parentheses, then curly brackets, and

we're gonna do something here. I'm gonna add a little comment . I'm gonna say sort by column and which column are we gonna sort ? Well, you're gonna say, let's say the, we have this due date in column A. We have a task, we have priority. Let's do it in D column for now. Last edit, that's gonna be four or d. And then we're gonna create another function , function on edit. And when we edit, we're going to have an event here. This is a variable that's gonna hold a little bit of data for us in these parentheses and in the curly brackets we can say variable row equals event GI row. This is sort of a little bit of magic where . We're gonna be able to know the range of this row. Actually. It's gonna be event range. Get row, sorry. Now we know the row of what we're editing.

And then we're gonna take spreadsheet app, which is just a base function of, that's just accessing all the core functions inside this spreadsheet . Get active spreadsheet . That's the entire file. Get sheet by get active sheet , get range . And now we want to go onto the row that we just are editing row. And in which column? Column four, we wanna set value And this can be new. That's lowercase new. Date and parentheses. Now this is gonna give us a timestamp and it's just gonna mark a timestamp, but I want to be very clear here. What timestamp is it gonna do in our spreadsheet? We can go up to file settings, and we have a time zone here, so we'll

do like Atlantic Save and Reload. But there is one other time zone , and that's an extensions app script . Go over here on the left side, project settings, and here you want to edit your time zone as well. Here's Atlantic time as well, so make sure both of those are the time zone you want because. This new date, this time stamp is gonna be the app script time zone . So let's test this out. Let's say we edit the due date for this top task. There is our last edit already created. Let's edit this to reports. Add new task. Maybe we can change this. To medium. Change this to medium, maybe change this to low. Just have a few timestamps here.

Now they have the date and the time, and so if we sort by column four, we should be able to sort them by last date. So let's do spreadsheet app, get active spreadsheet , get sheet by name. We are going to. Sort the tasks tab, sort and sort . Column four, and which way do we want to go? Ascending or descending. I'm gonna say descending or false. It's true. If you want us ending believe. So let's run this sort by date. May have to review permissions. And there are our last edit. But what if we want this function sort by date to happen anytime we're editing? So let's run this sort by date function just by typing in the name and these parentheses, save this here. And let's edit this to low

and now it's at top. That's the last edited . If we change this to, hi, check broken links. Hi. Perfect. It's working. So now we're auto automatically sorting by last edited date in these two steps we've created the last date. The timestamp and sort by date, and we added this function here in on edit. This function on edit is super cool. If you wanna learn more about automation, you want to dive deeper and really, really understand this so you can master it. Check out my course Master spreadsheet automation over on Udemy. I'll put a link in the description. 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.