For those who have more than 10 hidden sheets in one file
For those who want to save time on manually unhiding or deleting sheets
In managing weekly reports and other data in Google Sheets, do you find that the number of hidden sheets keeps growing?
Hiding sheets can be done with multiple selections, but what is troublesome is when you want to re-hide or delete sheets that have been hidden together.
In the case of Google Sheets, it is time-consuming to manually redisplay or delete them one by one.
Google Apps Script is useful in such cases.
Google Apps Script allows you to re-display or delete hidden sheets at once.
Google Apps Script may sound difficult, but you can use it by copying the script, so you do not have to write it yourself.
This article will show you how to take advantage of Google Apps Script to re-display hidden sheets together and how to delete them.
TOC
Script to reーdisplay hidden sheets in bulk
Script to redisplay hidden sheets in bulk
functionshowAllSheets() {var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // Get the currently open spreadsheetvar sheets = spreadsheet.getSheets(); // Get the list of sheets// Check all sheetsfor (var i =0; i < sheets.length; i++) {var sheet = sheets[i];if (sheet.isSheetHidden()) { // If the sheet is hidden sheet.showSheet(); // Unhide the sheet } }}
There is a copy button in the upper right corner of the code block (black screen).
Script Description
SpreadsheetApp.getActiveSpreadsheet()
A command to retrieve the entire spreadsheet that is currently open.
This is the part that specifies in which spreadsheet the script is running.
spreadsheet.getSheets()
Get all sheets existing in the current spreadsheet as an array (list).
All sheets are retrieved here, regardless of whether they are hidden or displayed.
for
Loop.
Check all retrieved sheets one by one to see if they are hidden.
sheet.isSheetHidden()
Function to check if a sheet is hidden or not.
Returnstrue if hidden.
sheet.showSheet()
Displays sheets in a hidden state.
Only sheets that are determined to be hidden by isSheetHidden()
After script execution
All sheets that were hidden will be re-displayed.
If there are only a few hidden sheets, it will not take long to re-display them one by one, but if there are a large number of sheets, Google Apps Script can save time.
Script to delete all hidden sheets in bulk
Script to delete all hidden sheets in bulk
functiondeleteHiddenSheets() {var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // Get the currently open spreadsheetvar sheets = spreadsheet.getSheets(); // Get the list of sheetsfor (var i = sheets.length -1; i >=0; i--) { // Loop through all sheets from the last to the firstvar sheet = sheets[i];if (sheet.isSheetHidden()) { // If the sheet is hidden spreadsheet.deleteSheet(sheet); // Delete the hidden sheet } }}
There is a copy button in the upper right corner of the code block (black screen).
Script Description
SpreadsheetApp.getActiveSpreadsheet()
Get the currently open spreadsheet.
spreadsheet.getSheets()
Get all sheets. Again, all sheets regardless of whether they are hidden or not.
for
Loop.
deleteHiddenSheets checks the list of sheets in reverse order. This is to prevent errors from occurring when deleting out of order listings.
sheet.isSheetHidden()
Function to check if a sheet is hidden or not.
Only hidden sheets are targeted for deletion.
spreadsheet.deleteSheet(sheet)
Delete hidden sheets. This command allows you to delete at once all the hidden sheets that you no longer need.
It is recommended that you back up your files before deleting them.
A script to delete hidden sheets is useful in this situation.
You no longer need the sheets that have been hidden
You want to organize because the file size is full and you can no longer copy sheets
How to use the script
スクリプトの使用方法
Toolbar – Extensions – Apps Script
Script Paste
Script Save
Execution
Sheet is re-displayed or deleted
STEP
Open the Apps Script Editor
Open Google Sheets, then click on “Extensions” in the menu and select “Apps Script” to open the editor.
STEP
Create the Script
function myFunction(){
}
is included from the beginning, so delete it and paste the previous script.
STEP
Save the Script
STEP
Run the Script
STEP
Completion
When the execution is completed, it is OK.
Verify that hidden sheets have been re-displayed or deleted.
If you’re running the script for the first time, you need to authorize it.
Therefore, press “Review Permissions.“
Detailed Authorization Steps
Press “Advanced.”
Press “Go to Untitled project (Unsafe).”
After that, press “Allow.”
Conclusion
Script to redisplay hidden sheets in bulk
functionshowAllSheets() {var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // Get the currently open spreadsheetvar sheets = spreadsheet.getSheets(); // Get the list of sheets// Check all sheetsfor (var i =0; i < sheets.length; i++) {var sheet = sheets[i];if (sheet.isSheetHidden()) { // If the sheet is hidden sheet.showSheet(); // Unhide the sheet } }}
Script to delete all hidden sheets in bulk
functiondeleteHiddenSheets() {var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // Get the currently open spreadsheetvar sheets = spreadsheet.getSheets(); // Get the list of sheetsfor (var i = sheets.length -1; i >=0; i--) { // Loop through all sheets from the last to the firstvar sheet = sheets[i];if (sheet.isSheetHidden()) { // If the sheet is hidden spreadsheet.deleteSheet(sheet); // Delete the hidden sheet } }}
The script introduced here is useful when you have a large number of hidden sheets.
Save time by letting Google Apps Script take care of the tedious work.
Our company offers support for improving work efficiency through the use of Google Apps Script. If you need assistance with Google Apps Script customization or error resolution, please feel free to contact us. We are fully committed to supporting your business improvements.
Comments