Auto Sort By Priority

Learn how to automatically sort your Google Sheets by priority using VLOOKUP and Google Apps Script. This video provides a step-by-step guide to set up priority sorting that updates with every edit.

In a previous video I showed you how to auto sort by date, but what if we just wanna auto sort by priority? Now here's some text and when we sort , we can sort the sheet by A to Z high. Wait low than medium or Z to a medium than low than high. No, we wanna do. Basically high, medium, then low, right? We want the highest priority at the top. So here's a little bit of a workaround. We can do a V lookup. And what we do a V lookup on is a little bit of a table . We can create a priority table here and say low, medium, high, and we can say 1, 2, 3, or 3, 2, 1, whichever. Way you want to go? So now we're looking at priority. With this V lookup, we're gonna search for this particular cell, C two.

We're gonna look in the range of A to B on priority. Our index is going to be the second column. So two, is it sorted? I like to put false here. It's optional, but that's my own priority. Then we copy paste this down and we see that medium is two, low is one, and high is three. So now we have a priority score. Let's say we can title this if we want, and now we can sort by highest, medium, low. They don't have to be in alphabetical order. But what if you wanted this to be automatic auto sort by priority? Every single time I edit the sheet, or every day, now we have a new column that we need to sort this D or fourth column.

Let's go to our extensions app script . In that previous video, I auto sorted by date. We wanna do priority now. Here's that sort by date. And our priority's gonna be fairly simple as well. Function sort by priority spreadsheet , app dot get active spreadsheet , get sheet by name. And here it's just the name of your spreadsheet sort . And we're looking at, let's double check the column. Column four or D, and we want it to either go highest to lowest, or lowest to highest. Let's look at our scores. We want to go highest to lowest, so we're gonna say false. Let's save this and click this dropdown menu to sort by priority, click, run, make sure we don't have any errors. If we have any errors. The most common are that we didn't. We didn't capitalize it correctly or we didn't add a dot somewhere,

so it's highest to lowest, even if we randomize this now it's random. Let's run it again, sort by priority. There it is highest to lowest. Now, how do we automate this? Well, first I wanna show you some errors. Let's say this is an uncapitalized a, and let's try to run this sort by priority. We're gonna get this type error spreadsheet app dot get active spreadsheet is not a function , so it doesn't tell you that it's not capitalized. It just tells you that this get active spreadsheet is not a function . And why that is is 'cause it has to be a capital A get active with a capital A spreadsheet with a capital S. If we don't have our parentheses, let's run it. And it also says this is not a function. But it's because we don't have parentheses there. So let's automate this.

Now go over to triggers. On the left side, add trigger . On the bottom right, choose which function . We'll choose the sort by priority. Now we can do event source, time driven, and do every hour click save, and that will just automatically, every hour sort it. But what if we wanted to do it on every single edit? Anytime we added. Something to a cell. Deleted something from a cell, deleted a row. Well, we're gonna choose now from spreadsheet and click on edit. In this select event type. Click save. Now I'm gonna add new task. I'm gonna say hi. However, we don't have a score here, so we do need to copy paste this all the way down. And now did you see that jump up to the high section? Pretty cool.

Right now it's automatically sorting by priority. Anytime we edit any of the sheet, enjoy. 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.