0

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Ops. Thanks, I repurposed a script and left that in there by mistake. I edited my question. Now getting error Cannot find method deleteColumns((class))
The issue is just as says. The object sheet does not have that method. Why don't you try console logging sheet and see what's inside?
This was the problem (var i = 0; i <= arr.length; i++) changed to (var i = 0; i <= arr.length -1; i++) and now works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.