0
votes

I am trying to write a script to delete columns by passing an array of column numbers getting error

Cannot find method deleteColumns((class))

I'm pretty sure this is the problem

for (var i = 0; i <= arr.length; i++){
      sheet.deleteColumns(arr[i]);
      };

Thanks for any help on this

function DMC_n(){
   DMC('Elements', [1,2]);  
}

function DMC(shtName, arr){
  var sheet =  SpreadsheetApp.getActiveSpreadsheet().getSheetByName(shtName);
  var range = sheet.getDataRange();
  var values = range.getValues();

  for (var i = 0; i <= arr.length -1; i++){
      sheet.deleteColumns(arr[i]);
      };
}
1

1 Answers

1
votes

Your function DMC() defines three parameters, where the last one, "arr", is not given from your function call:

DMC('Elements', [1,2]);

So the third argument is undefined.