0
votes

In spreadsheet, I have a sheet named "Sheet1" which is a summary of all sheets I've created. I'm trying to delete a specific row from "Sheet1" and it's corresponding sheet by name. The "x" is a variable in the script, I can successfully remove row "5" from "Sheet1", but can not remove sheet "5" from worksheet.

function myFunction () {
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1AGDGqi7hh-vr96EuCCDl0PqdcVtwweoWpB2Lj0ajHR4/edit#gid=0");
var sheet = ss.getSheetByName("Sheet1");  
var x = 5; 
sheet.activate().deleteRow(x);  
var source = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(x);
SpreadsheetApp.getActiveSpreadsheet().deleteSheet(source);  
1

1 Answers

1
votes

You don't even need to activate the sheet before deleting it.

var source = ss.getSheetByName("Sheet"+x);// get the sheet object
ss.deleteSheet(source);// done !