Insert or add a row

Here is a tip how to add a row. 

  

Source code

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

  sh.insertRows(4);
  sh.insertRowAfter(1);
  sh.insertRowBefore(1);
}

 

Format

SheetObject.insertRows(rowIndex)
SheetObject.insertRowAfter(afterPosition)
SheetObject.insertRowBefore(beforePosition)

 

Parameters

(1) insertRows

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

(2) afterPosition

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

(3) beforePosition

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

 

Responses

None

Leave a Comment