Skip to content
Advertisement

Sheet with name as number not being returned with getSheetByName in For loop

I am having trouble getting this for loop to work correctly:

for(var d = 0; d < sheetno/2; d = d + 1){
 var dsheet1 = print_ss.getSheetByName(d);
 var dsheet2 = print_ss.getSheetbyName(d+100);
 print_ss.deleteSheet(dsheet1);
 print_ss.deleteSheet(dsheet2);
  
}

I have a sheet named “0” and another named “100” and so on (dependent on how many sheets are in the spreadsheet).

The script works for the first sheet (i.e. finds the sheet named “0”):

var dsheet1 = print_ss.getSheetByName(d);

But it returns a “TypeError: print_ss.getSheetbyName is not a function” for the following line:

var dsheet2 = print_ss.getSheetbyName(d+100);

What am I doing wrong?

Advertisement

Answer

You have a typo. It should be getSheetByName but not getSheetbyName

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement