Insert or add multiple rows

Here is a tip how to add multiple rows.

 

Source code

function insertRows() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getActiveSheet();

  sh.insertRows(5, 2);
  sh.insertRowsAfter(1, 3);
  sh.insertRowsBefore(1, 4);
}

 

Format

SheetObject.insertRows(rowIndex, numRows)
SheetObject.insertRowsAfter(afterPosition, howMany)
SheetObject.insertRowsBefore(beforePosition, howMany)

 

Parameters

(1) insertRows

rowIndex … The target row’s number. New rows will be added after this target row.

numRows … Config the number of new rows that will be added.

(2) afterPosition

afterPosition … The target row’s number. New row will be added after this target row. (This is same with “rowIndex”)

howMany … Config the number of new rows that will be added.

(3) beforePosition

beforePosition … The target row’s number. New row will be added before this target row.

numRows … Config the number of new rows that will be added.

 

Responses

None

Leave a Comment