Delete sheet by index number

Here is how to delete sheet by index number.

 

Source code

function delSheetByIndex(){
  // Get Spreadsheet Object
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();

  // Get target sheet object
  var sheets = spreadsheet.getSheets();
  var sheet = sheets[0];

  // Format
  spreadsheet.deleteSheet(sheet);
}

 

Format

SpreadsheetObject.deleteSheet(sheet)

 

Parameters

sheet … Sheet object

 

How to get a sheet object by index number?

Just only 2 steps.

(1) Get all sheets’ objects

    function getSheetsOjbects(){
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var sheets = ss.getSheets();
    }

(2) Identify the targeted sheet by index number

SheetsObjects[index]

If you want to know the detail, please refer the following post;

Get objects of all sheets

Leave a Comment