How to Delete Every Checked Row
Learn how to quickly delete every checked row in Google Sheets using App Script with a simple function. This tutorial walks you through the process step-by-step, ensuring you can automate your spreadsheet tasks efficiently.
You wanna delete every checked row, but we wanna do it very quickly instead of having to go to a completed row here that is checked and saying, Hey, delete this row. We wanna actually just delete them all at one time. We can do this with App Script . Go up to Extensions app script . Once you're here, we're gonna start writing a function variable. SS equals spreadsheet app.gi active sheet variable rows is going to equal ss.gi max row. That's every single row in the entire sheet that we're on. And we're gonna create a variable checked equals SS GI range . And let's check just the third row right now. We're going to iterate this three, but for right now, let's just check that it's correct. We wanna check just one of these columns.
So we wanna say the D column here. So we're gonna look at row three comma four. That's it. And then we're gonna write is checked with parentheses, and now if checked, so this is going to be either true or false. It's checked or it's not checked. And if it's true or we're going to do something here else, if it's false, we're gonna do something here. So we can write logger log. Nope. And up here for if it is true, we can write logger log. Yes. So let's save this and run it. The very first time we run it, we are going to have to authorize it, just have to review permission, and then we only have to do this for the very first time. And it says, Nope. Why is that? Because row three, let's go check. Row three is not checked.
Let's check it and run it again. Say yes. So now we know if it's checked or not. What we want to do is actually delete the row that's. Check. So SS delete row , and in this case it's gonna be three, but we want to iterate through every single row so we can't hard code or write three and then change this to four, then changes to five. We wanna do that with a four loop. So let's create a for loop here. For I equals one semicolon I is less than or equal to I. Rows, all of the rows in the sheet. Another semicolon I plus plus, and now put that all in curly bracket. So now inside of this for loop, we're gonna cut and paste everything.
Let's format this document so you can see a little easier. So now this I is gonna be iterating. It's gonna go through here, do whatever it needs to do, then add one to I. So two. And look for all of them. So we're gonna change this three to an I and delete row to I as well. So we'll start on row one and go through all of the rows. Save that. Now what should happen, let's go back and look, is row 3, 5, 6, 7, and 11 should be deleted. So we'll. Select our function up here if we have other functions . My function , if you only have one function and click run, and let's go back and see these are being deleted. I think except one of them. See if we've run it again. If it'll have that. It deleted it that time.
Steve and Kevin. Let's just double check that. It's just doing Steve and Kevin. Steve and Kevin are gone. There we go. So now we're deleting all of the rows that are checked, and it's just this few lines of code here. 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.