A Google Apps Script function I wrote

I code in javascript all the time, but it’s usually stuff that only I would find useful. Additionally, the code is often too sloppy to make sense. But I cleaned up this function and I’m happy to share it with the world, in hopes that it might save other folks some time.

function CycleSheets()
If you’re like me, you’ve got too much data in your workbook and it’s maddeningly slow to scroll through all the sheets

If there are several sheets that you want to delete, it’s a pain to go navigate to each sheet and right click to delete and then confirm in an alert box.

So, this is a function that will show the user each sheet by name and size, giving them the choice as to whether or not to delete that particular sheet.
After all the sheets have been cycled through, the user will be shown a list of the sheets they’ve selected to delete, at which point they can confirm and delete or cancel.

function cycleSheets(){
   var ui       =   SpreadsheetApp.getUi();
   var ss       =   SpreadsheetApp.getActive();
   var sheets   =   ss.getSheets();
   var sheetCt  =   sheets.length;
   var delArr   =   [];
   
   for (var a = 0; a < sheetCt; a++){ var thisSheet = sheets[a];
      var thisCount =  a + 1;
      var sheetID   =  'Sheet ' + thisCount + '/' + sheetCt + ', named: ' + thisSheet.getName();
      var sheetData =  sheetID + '\nSheet contains ' + thisSheet.getLastRow() + ' rows.';
      var deleteYN  =  ui.alert('Delete this sheet?', sheetData, ui.ButtonSet.YES_NO_CANCEL);

      if (deleteYN  == ui.Button.YES)    {
         delArr.push(thisSheet); Logger.log('Sheet ' + thisCount + ' will be deleted.');
      }
      if (deleteYN  == ui.Button.NO)     {
         Logger.log('Sheet number ' + thisCount + ' will *not* deleted.');
      }
      if (deleteYN  == ui.Button.CANCEL) {
         var a = sheetCt + 1; ui.alert('Cancelled!'); return
      }
      if (deleteYN  == ui.Button.CLOSE)  {
         var a = sheetCt + 1; ui.alert('Closed and cancelled!'); return
      }
   }
   if (delArr.length > 0)   {
      var sheetNames   =   '';
      for (var b = 0; b < delArr.length; b++)   {
         var sheetNames = sheetNames + delArr[b].getName() + '\n'
      }
      var deleteConf   =    ui.alert('Are you sure you want to delete all of these sheets?', sheetNames, ui.ButtonSet.YES_NO);
      if (deleteConf   ==   ui.Button.YES){
         for (var c = 0; c < delArr.length; c++){
            ss.deleteSheet(delArr[c]);
         }
         ui.alert('You deleted ' + delArr.length + ' sheet(s). \nNow there are ' + ss.getSheets().length + ' sheets left.')
      }
      else {   
         ui.alert('You cancelled this deletion.')
      }
   }
   else {
      ui.alert('You didn\'t choose any sheets to delete!')
   }
}

Anyway, I hope you get some use out of it. Tweet me @skweeds to let me know how it works out!