How to Lock a Tab In Place in Google Sheets

Learn how to lock a tab in place in Google Sheets using Google Apps Script, ensuring your important sheets remain in a specific order even when changes are made.

Here's how to lock a tab in place in Google Sheets. We have employees here, we have past employees. We could be adding new sheets, we could be moving sheets around, but we want to make sure this employee's tab is always at the beginning. Here's how to do it. Go up to Extensions app script . We're gonna call this function . Set my tab. We are gonna get the employee sheet, so variable employees equals spreadsheet app dot get active spreadsheet . That's the entire workbook. Get sheet by name and we're gonna make sure this is employees. And then we're gonna set this employees as the active tab activate. With Get active sheet , and then we're gonna do spreadsheet app dot, get active spreadsheet , getting the entire spreadsheet again. Move active sheet and we're going to move it to one.

Now, this function doesn't run all the time. We have to create a trigger , so if we want to test it, we can move employees here. Run, set my tab. If you have to authorize at the first time, it's fine. It won't have ask you to authorize every time, and now employees is in the first spot. So how do we get this to trigger every single time we go over to left side triggers? On the bottom right click, add trigger , choose which function , which will be our set my tab. If you have other functions , it'll be here in a dropdown list. Then we're going to select event type on. Change on change is different than on edit. On edit, you're editing the value of a cell On change, you're changing the structure of the spreadsheet tab. you could be inserting a row, inserting column, adding sheets, deleting sheets, removing things.

All of the structure of your workbook is going to be on Change so we're gonna save it there. And now we have our automation here. You can go back to our sheet and move something around and automatically it's moving back. If you want to delete this automation, we can go back to our app script extensions go to triggers, and over on the right side there's three dots you can delete trigger if you wish, delete forever. There you go. That's how to lock a tab in place in its specific index . If you need to change that index , maybe it needs to be the second spot. You can always change this one at move active sheet to two or three, whichever tab. Place you want it to. If you're looking to get more automations, enjoy Google Sheets more. Get more out of it. Subscribe here on YouTube to better sheets.