How to Lock Multiple Tabs at Start of Sheets List in Google Sheets
Learn how to lock multiple tabs in Google Sheets using Apps Script, allowing for better organization and automation of your spreadsheet workflow.
So in a previous video, I showed you how to lock a tab. Now we're gonna show you how to lock multiple tabs. So I'm gonna go over to Extensions, Apps Script , and do this automatically. We have a function setMyTab. We're going to say the one that we want to have set is sales. Variable sales equals SpreadsheetApp .getActiveSpreadsheet. And then we're going to add, uh, getSheetByName. And it's just gonna be sales in all caps. We're gonna say sales.activate, and we're gonna use Spreadsheet dot… s-sorry, SpreadsheetApp.flush to say, "Hey, execute that stuff." Then we're gonna say variable active equals SpreadsheetApp .getActiveSheet. And we're gonna use SpreadsheetApp .getActiveSpreadsheet again, getting the entire file.
M- We're gonna move active sheet to one. Now, this position one means that it's going to be the m- left-most. And say we wanna do template as well. Well, we're gonna copy and paste this function . It's all in setMyTab. We can even call this setMyTabs. Now we need to do that for a different one, which is template . So we'll write template here as a variable. We'll write template as the name. And then we're gonna change sales.active to template .active, and this active can stay the same. Actually, we don't even need this part, this active, 'cause we're just saying get active spreadsheet , move active sheet, and then we're gonna change this one to a two. So we're gonna say, "Hey, move… get sales, make it the active sheet, activate it."
Move it to one, then take template , activate it, and move to two. So let's do save. I want to actually move these across over, and right now instructions is the first one, settings, but I want template and sales there. So let's run it. You may need to authorize it f- the very first time you run it. And let's go back to our sheet and see that sales is in the first place, template is in the second place. And we can copy and paste this over and over and over again for however many tabs you want in a particular place, first, second, third, fourth, fifth, and so on and so forth. Let's automate this so that every night it runs it without us having to come into this Apps Script and run it. Over on the left side, click Triggers. On the bottom right, click Add Trigger .
We're gonna choose the function to run. If you have more than one function , you're gonna have to set it in the dropdown menu. But if it's the only one you have, it'll already be set. Select Event Source. We don't want it from the f- spreadsheet , but we actually want it time-driven, and we wanna say every day at the end of the day, so like 7:00 to 8:00 PM, or you can say, "Hey, every day in the start of the day we want it." Click Save. If you need to authorize, you might have to authorize then and there. And you'll see this trigger here. Again, you can get back to this by closing here. You can say Extensions, Apps Script . Just in case you want to delete this trigger , you're like, "Hey, I don't need these in these same place anymore," go to Apps Script, go on the left side, go to Triggers, and you'll see the row eventually. There we go.
And you'll see an edit icon, a little tiny pencil, but next to it is three dots. That three dots allows you to delete trigger , and then we can delete forever if you ever need to delete it. That's how you do it. You can't delete other people's triggers, so if somebody else set this up and you need to delete their trigger , you can't. Gotta have them trigger -- You gotta have them delete their own trigger . Hopefully, that was a fun way to lock multiple tabs. 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.