How to Delete Every Blank Row

Learn how to efficiently delete every blank row in Google Sheets using Google Apps Script. This tutorial guides you through the process step-by-step, ensuring you can automate row deletion effectively.

Here's how to delete every blank row. We have a table and we have some blank rows here, but we also have blank rows on the bottom. We don't wanna delete each and every one of these. We can use app script to do that for us. Extensions app script , open it up and you'll see this function , my function . Let's create a variable SS equals spreadsheet app to get active sheet . And then we're gonna do Ss get range . And this range. Let's look at first, the first row. The first column, the number of rows is only gonna be one. We're gonna look at one row at a time, and the number of columns is actually gonna be ss.gi blast column. So that gets us the total number of columns and the entire row here, and we can say is blank, this will return true or false.

So let's call this blank equals and. This blank will either be true or false, so we can use an if statement if blank. So if it's true, it is blank. Let's do something else. Let's do something else for right now. We're gonna do logger log. Yes. It's blank just to see if it's blank. And if it's not blank, we'll do logger log. Nope. Now we're gonna hit run right now before we automate this to go through every single row. But let's hit run and see what happens. Nope, it's not blank. So this means the very first row, row one is not blank. Let's go back to our sheet and see which is the first blank. Row three. Let's go check that. Let's change this. One, two, a three. Save it. Run it and it says yes, it's blank. So we could put in here instead of logging.

Yes, it's blank. We can delete that row, but we want to also iterate through every single row. So we're gonna create a four loop. A I equals zero I is less than what? Well we're gonna get how many rows there are rows equals. Ss get last row rows I plus plus this iterates through every single row from zero. So actually we may wanna do one here, a then row plus one, and we can now put all of this inside of this for loop. And instead of a number here for row, we do row rather I. So I is the iterator here, it's starting at one and it's going until it's over rows plus one.

So we can change this instead to less than or equal to rows rose. And now we're gonna get every single row and we want to delete the ones that are blink. So if it is blink, we'll go SS dot range I one. One SS Doet. Last column. We'll just copy this code just before the is blank. Actually we'll do delete row . Ss delete row , and which row we're gonna do I. So now if we run this function , we should delete every blank row and there it goes. It's deleting every blank row. it doesn't delete all of the extra rows down here because our get last row here is

getting the last row that has data in it. If you wanna delete even beyond the data , we're gonna get get Max Rose. Change that and save it. Click run. And this should delete all of the extra rows here. There. It's deleting each and every row as it goes through. But this is also making sure that it is completely blank. So even rows that are incomplete are gonna stay. 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. 10 Google Sheets I Wish Someone Would Make What's Better Than Google Sheets? Automate Google Sheets With Zero Experience SheetOps