How to Add Multiple Columns with Apps Script

Learn how to add multiple columns in Google Sheets using Apps Script in this informative tutorial. Discover the simple adjustments needed to automate the process and enhance your spreadsheet functionality.

In a previous video, I showed you how to add a column for habit checking automatically, where we add this column with some app script . I'm gonna go and show you that app script , but right now I'm gonna show you how to add multiple columns. So in our app script , we have a function add column. We have our variable last column, which gets the last column in our sheet, and we insert a column after the last column, and then we set the value to new date. Well, what if we wanna add two new columns? We only have to do. Two things differently. Our insert column after changes into insert columns after, and our last column we add at the end a comma and a two. So if you see here, this little helper shows us that insert columns after takes.

Two things we need to know where is the column we want to add afterward and how many. And so we just say two here, we can say three or four or five. And so this is gonna insert a column, two columns after the last column. So let's hit run and see. It's completed it and. You see we have our date and then a blank. So if you wanna add that date more. So this is today. It already did it automatically before. If we wanna add one more date, maybe we wanna keep it blank, but maybe we do want the date. We can set a new value to last column plus two, and let's delete these two dates. Have this actually right here at the end so we can see if it adds it or not. Let's hit run again and see. We have our two new columns with the date on both of them, so there you go.

That's how to add columns automatically. 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.