Quinten De Wilde
Quinten De Wilde

Reputation: 25

TypeError: Cannot read property 'getRange' of null deleteRows

I have this code to delete multiple specific row in a table

function deleteRows() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = ss.getSheetByName('comp');
  var r = s.getRange('A:A');
  var v = r.getValues();
  for(var i=v.length-1;i>=0;i--)
    if(v[0,i]=='is a unique address')
      s.deleteRow(i+1);
};

The sheet name is correct, the column is populated and the text bit is also correct.

This is the error:

TypeError: Cannot read property 'getRange' of null
deleteRows  @ Code.gs:4
A B
a is a duplicate address, seen 13 times
b is a duplicate address, seen 14 times
c is a duplicate address, seen 7 times
d is a duplicate address, seen 3 times
e is a unique address
f is a duplicate address, seen 2 times
g is a duplicate address, seen 11 times
h is a duplicate address, seen 2 times
i is a duplicate address, seen 4 times
j is a unique address

Upvotes: 0

Views: 480

Answers (1)

JPV
JPV

Reputation: 27242

Did you check if there are no trailing spaces in the tab name ?

Also, a bit further in the code (and assuming the 'unique adress' is in column A) so may have to change this line

if(v[0,i]=='is a unique address')

to

if(v[i][0].indexOf('is a unique address')>-1)

and see if that helps?

Upvotes: 1

Related Questions