Ariel Ecker
Ariel Ecker

Reputation: 11

Insert Blank Rows after Each Row in Google Sheets

I have this script and work fine. But I have one question: How to add rows with an text instead of white?

function addRows(){
  var startRow = 1;
  var sheet = SpreadsheetApp.getActiveSheet();
  var rows = sheet.getDataRange();
  var numRows = rows.getNumRows();
  for (var i=numRows; i > -1; i--) {
    sheet.insertRowsAfter(i + startRow, 2);
  }
}

Upvotes: 1

Views: 289

Answers (1)

Cooper
Cooper

Reputation: 64062

Try this:

function addRows(){
  var sheet=SpreadsheetApp.getActiveSheet();
  var data=sheet.getDataRange().getValues();
  var d=0;
  data.forEach(function(r,i){
    sheet.insertRowAfter(i+1+d++)
  });
}

Animation:

enter image description here

Upvotes: 1

Related Questions