Google Sheets – Adding Multiple Rows Using Script

google sheetsgoogle-apps-script

I have this simple Google Sheets script that adds a row after every already existing one. What do I have to change to for example add 12 rows?

function addRows(){

  var sheet = SpreadsheetApp.getActiveSheet();

  var rows = sheet.getDataRange();

  var numRows = rows.getNumRows();

  for (var i = 1; i <= numRows*2 - 1; i+=2) {

   sheet.insertRowAfter(i);

  }

}

Best Answer

There are several ways to change your script. You could use insertRows(nowIndex, numRows) among other methods.