title: How to step through google script
body: <p>I am trying to write a Google Sheets script macro.  How do I step through it to understand why the time is being exceeded?
  My problem is the loop, when I set the iteration max(scenarios) to 46, the code seems to run fine, taking about 1-2 seconds.  When the max is set to 47, it dies with max execution time exceeded (4-5 minutes).  Whats going on?</p>
  
  <pre><code>function testing() {
  
    var aa = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Run 
    Program");
  
    var scenarios = aa.getRange("H19").getValue();
  
  
  
    for (i = 1; i &lt;= scenarios; i++){
  
    var ss = 
    SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet6");
  
    var range = ss.getRange("b6:u6");
    var min = 1  ;
    var max = 20 ; 
    var numbers = []
      for (var i = min; i &lt;= max; i++) {             
        numbers.push(i);
    }  
  
  
    shuffleArray(numbers)
    var counter = 0;
    for (var x = 1; x &lt;= range.getWidth(); x++) {
      for (var y = 1; y &lt;= range.getHeight(); y++) {
        range.getCell(y, x).setValue(numbers[counter]);
        counter++;
      }
    }
    var range = ss.getRange("v6:ao6");
    var min = 21  ;
    var max = 40  ;
    var numbers = []
      for (var i = min; i &lt;= max; i++) {
       numbers.push(i);
    }
    shuffleArray(numbers)
    var counter = 0;
    for (var x = 1; x &lt;= range.getWidth(); x++) {
      for (var y = 1; y &lt;= range.getHeight(); y++) {
        range.getCell(y, x).setValue(numbers[counter]);
        counter++;
      }
    }
    var range = ss.getRange("ap6:at6");
    var min = 41  ;
    var max = 45  ;
    var numbers = []
      for (var i = min; i &lt;= max; i++) {
       numbers.push(i);
    }
    shuffleArray(numbers)
    var counter = 0;
    for (var x = 1; x &lt;= range.getWidth(); x++) {
      for (var y = 1; y &lt;= range.getHeight(); y++) {
        range.getCell(y, x).setValue(numbers[counter]);
        counter++;
      }
    }
    }
  //  function Chart4() {
    var spreadsheet = SpreadsheetApp.getActive();
        spreadsheet.getRange('A1').activate();
        spreadsheet.getSheetByName('Chart4').showSheet()
       .activate();
        spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Chart4'), 
  true);
  };
  </code></pre>