I have two spreadsheets, source and destination. In source I have data sheet and in destination I have archive sheet. In data sheet J column contains percentages. I am trying to workout a script which automatically copies the range (A:I) of the rows that has greater than 10% in the J cell to append in the archive sheet.
I'm stuck at this point:
function CopyRange() {
var sourcespread = SpreadsheetApp.openById('aaa'); //replace with source ID
var sourcesheet = sourcespread.getSheetByName('bbb'); //replace with source Sheet tab name
var destspread = SpreadsheetApp.openById('ccc'); //replace with destination ID
var destsheet = destspread.getSheetByName('ddd'); //replace with destination Sheet tab name
var testrange = sourcesheet.getRange('J:J');
var testvalue = (testrange.setNumberFormat("0.00").getValues());
var data = [];
var j =[];
//Condition to check in J:J, if true, copy the same row to data array
for (i=0;i<testvalue.length;i++) {
if (testvalue[i] >= 10) {
data.push.apply(data,sourcesheet.getRange(i+1,1,1,3).getValues());
//Copy matched ROW numbers to j
j.push(i);
}
}
//Copy data array to destination sheet
destsheet.getRange(destsheet.getLastRow()+1,1,data.length,data[0].length).setValues(data);
}
I'm getting error:
TypeError: Cannot read property 'length' of undefined (line 19, file "cp3")
1.8>10
will evaluate to false. This is why you are getting the error. – soMariobbb
) or the destination sheet (ddd
) ? – soMario