title: Google Script: Issue deleting Specific Sheet in google spreadsheet
body: <h1>Situation:</h1>
  
  <ul>
  <li>I have a spreadsheet with 20 sheet.</li>
  <li>I have other script that copy sheets from other spreadsheet every days to this spreadsheet-</li>
  <li>I need to delete every days some specific sheet from a particular spreadsheet.</li>
  </ul>
  
  <h1>Problem:</h1>
  
  <p>When the script ends to clear the sheets, the spreadsheet hangs and I have to exit and re-enter to the spreadsheet.</p>
  
  <p>I'll appreciate if anyone can help to tunning this script to work without hangging the spreadsheet.</p>
  
  <h1>Script:</h1>
  
  <pre><code>    function shellDeleteSheets(){
       var sheets = ['Sheet1','Sheet2','Sheet3','Sheet4','Sheet5']; 
       for (var s in sheets){
       deleteSheetName(sheets[s]);
        }
      }
  
        function deleteSheetName(stname) {
        var ss = SpreadsheetApp.getActiveSpreadsheet();
        var sh = ss.getSheetByName(stname);
        if(!sh) {
          return;
        }
        ss.setActiveSheet(sh);
        ss.deleteActiveSheet();
        Utilities.sleep(400);
        SpreadsheetApp.flush();
  
      }
  </code></pre>