title: Iterate through a range and set values
body: <p>In Google Sheets, I'm trying to input numbers in sequential order after prompting the user for the starting range and number of rows from that range.  If the user types the cell "C5" for example and inputs 5 rows, the result should be from cells C5 - C10 (1, 2, 3, 4, 5)</p>
  
  <p>I found a way to input the same value in all the rows but I can't seem to iterate through the range the user gives and set different values in each cell.  </p>
  
  <pre><code>function placeInCell() {
     var mySheet = SpreadsheetApp.getActiveSpreadsheet();
     var sheet = mySheet.getSheetByName('Second');
  
     var ui = SpreadsheetApp.getUi();
     var result = ui.prompt('What cell to start with?', 
                                      ui.ButtonSet.OK);
     var result2 = ui.prompt('How many cells?', ui.ButtonSet.OK);
  
     // Process the user's response.
     var button = result.getSelectedButton();
     var cell = result.getResponseText();
  
     var button2 = result2.getSelectedButton();
     var numCells = result2.getResponseText();
  
     var cellRange = sheet.getRange(cell); 
     cellRange = cellRange.offset(0, 0, numCells);
  
     //iterate through the range given by the user and set values 
     //in each row
     for (var i = 0; i &lt; numCells; i++){
        cellRange.setValue(i);
     };
  }
  </code></pre>