I am using the below filter function to copy data from one sheet to another, filtering out so that it only copies data if column AE = TRUE. When I use this script, it gives me the error:
TypeError: Cannot call method "getRange" of null. (line 9, file "Code")'
I am not sure what the getRange section means.
function myFunction() {
var sss =
SpreadsheetApp.openById('1V3Tl4h43AC92K4gQtvdZ07k01QJOnfwSD1BKKTziHJU');
var ss = sss.getSheetByName('<20 Filter');
var range = ss.getRange('A:AE');
var data = range.getValues();
var tss =
SpreadsheetApp.openById('1AKL81cN5QWTWSsSfuMGcFRED5QpeAK022k8VwrPl7sA');
var ts = tss.getSheetByName('Zones >20 Riders');
ts.getRange(ts.getLastRow()+1, 1, data.length,
data[0].length).setValues(data);
var range = ts.getRange(ts.getLastRow()+1, 1, data.length,
data[0].length)
var rawData = range.getValues() // get value from spreadsheet 2
var data = [] // Filtered Data will be stored in this array
for (var i = 0; i< rawData.length ; i++){
if(rawData[i][30] == "TRUE")
{
data.push(rawData[i])
}
}
}
Or could I use this script?
function myFunction() {
var sss = SpreadsheetApp.openById('1V3Tl4h43AC92K4gQtvdZ07k01QJOnfwSD1BKKTziHJU'); //replace with source ID
var ss = sss.getSheetByName('<20 Filter'); //replace with source Sheet tab name
var range = ss.getRange('A:AE'); //assign the range you want to copy
var rawData = range.getValues() // get value from spreadsheet 1
var data = [] // Filtered Data will be stored in this array
for (var i = 0; i< rawData.length ; i++){
if(rawData[i][30] == "TRUE")
{
data.push(rawData[i])
}
}
var tss = SpreadsheetApp.openById('1AKL81cN5QWTWSsSfuMGcFRED5QpeAK022k8VwrPl7sA'); //replace with destination ID
var ts = tss.getSheetByName('Zones <20 Riders'); //replace with destination Sheet tab name
ts.getRange(ts.getLastRow()+1, 1, data.length, data[0].length).setValues(data);
}
But it gives me the error:
TypeError: Cannot read property "length" from undefined. (line 15, file "Code")