Insert or add multiple columns

Here is a tip how to add multiple columns.

 

Source code

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

  sh.insertColumns(5, 2);
  sh.insertColumnsAfter(1, 3);
  sh.insertColumnsBefore(1, 4);
}

 

Format

SheetObject.insertColumns(columnIndex, numColumns)
SheetObject.insertColumnsAfter(afterPosition, howMany)
SheetObject.insertColumnsBefore(beforePosition, howMany)

 

Parameters

(1) insertColumns

columnIndex … The target column’s number. New column will be added after this target column.

numColumns … Config the number of new columns that will be added.

(2) afterPosition

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

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

(3) beforePosition

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

numColumns … Config the number of new columns that will be added.

 

Responses

None

Leave a Comment