title: Loading multiple sheets within for loop causes script to freeze (Google Apps Script)
body: <p>I have had this issue multiple times and was wondering if I am doing something wrong. Here is my code:</p>
  
  <pre><code>function createPersonalSheet() {
  var persons = new Array("KDS", "BH");
  var ss = SpreadsheetApp.openById("0AtZdrPVig0OadFZjZlYxOEI3WVBwS1NfN2cwMlpaNWc");
  
  for(j=0;j=1;j++) {      
    var data = getData(persons[j]);
    var sheet = ss.getSheetByName(persons[j])
    var end = sheet.getMaxRows()-3;
    var range = sheet.getRange(4, 2, end, 14);
    range.clearContent();
    var range = sheet.getRange(4, 2, data.length, data[0].length);
    range.setValues(data);
  }
  </code></pre>
  
  <p>It runs if I only add one value in the persons array, but as soon as I add a second, the script stops working and it even crashes the spreadsheet (I have to refresh). Any ideas? I tried Utilities.sleep(1000) at the end of the for loop to give it some time but no effect.</p>
  
  <p>Any help would be deeply appreciated</p>