Show or Hide a Sheet with Apps Script

To show or hide a sheet using Google Apps Script, you have the methods showSheet and hideSheet.


Hide a Sheet

The following function hides the sheet named Example using the hideSheet method:

function hide() {
  const sheet = SpreadsheetApp.getActive().getSheetByName('Example');
  sheet.hideSheet();
}

Show a Sheet

The following function shows the sheet named Example using the showSheet method:

function show() {
  const sheet = SpreadsheetApp.getActive().getSheetByName('Example');
  sheet.showSheet();
}

After using this function, the sheet's tab appears at the bottom of the page.

To also display the sheet on the screen, add the activate method to your code:

function show() {
  const sheet = SpreadsheetApp.getActive().getSheetByName('Example');
  sheet.showSheet();
  sheet.activate();
}

Note that the content of this last function can be shortened as follows:

function show() {
  SpreadsheetApp.getActive().getSheetByName('Example').showSheet().activate();
}