Hide or show a sheet in Google Sheets using Apps Script

In this tutorial, I will show you how to hide a sheet in a Google Sheets spreadsheet using Apps Script. I will also show you how to show or activate a previously hidden sheet.

The function hideSheet() below accepts one parameter, which is the name of the sheet to hide.

First, we get a reference to the sheet by using the getSheetByName(sheetName) method of the Sheet class and then we hide it using the hideSheet() method.

function hideSheet(sheetName) {
 SpreadsheetApp.getActive().getSheetByName(sheetName).hideSheet();
}

To use the function, just call it with the name of the sheet to hide.

// Hide a sheet named "WIP Analysis"
hideSheet("WIP Analysis");

To show a previously hidden sheet, you can either use the showSheet() method or the activate() method. If you use the showSheet() method, then the sheet will be shown but it will not be activated. If on the other hand, you use the activate() method, the sheet will be shown and will also be made active.

function showSheet(sheetName) {
 SpreadsheetApp.getActive().getSheetByName(sheetName).showSheet();
}

function activateSheet(sheetName) {
 SpreadsheetApp.getActive().getSheetByName(sheetName).activate();
}

Conclusion

In this tutorial, I showed you how to hide or show a sheet in Google Sheets using Apps Script.

Thanks for reading!

Master Google Sheets Automation

Sign up to receive exclusive Automation tips and tutorials!
I'll send you actionable tips on automating tasks with Google Sheets and coding with Apps Script. You'll also be notified whenever new content is published.
PLUS: Get instant access to my Birthday Reminder Template! 🎂
By signing up you agree to the Privacy Policy & Terms.

Have feedback for me?

I'd appreciate any feedback you can give me regarding this post.

Was it useful? Are there any errors or was something confusing? Would you like me to write a post about a related topic? Any other feedback is also welcome. Thank you so much!