0

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);

  }

}
2

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

  • Thanks for the link. I found there the answer I was looking for. :) – Jake St Mar 21 '18 at 14:58
0
function onEdit(e){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('addnewrow');
  var range = e.range;
  var row = range.getRow();
  sheet.insertRowAfter(row);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.