I am trying to copy some data range (if-condition based) from one sheet to another sheet and sort it. There is no error when debugging the code. When running script, data is not copied and sorted. If I skip the sorting line (r.sort()...), then data is copied to another sheet successfully. I want to do both copy and sort the data. Please help me to solve it.
function sort_list() {
var s1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('list');
var s2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sorting');
var copy1 = s1.getRange("B5:B180");
var copy2 = s1.getRange("M5:M180");
var locate = s2.getRange(2,3);
var toplot = locate.getValue();
Logger.log('To plot is '+ toplot);
var unitsystem = s2.getRange(3,3);
var measure = unitsystem.getValue();
Logger.log('torque '+ measure);
if(toplot == 'condition1' && measure == 'condition2'){
copy1.copyValuesToRange(s2, 4, 4, 5, 180);
copy2.copyValuesToRange(s2, 3, 3, 5, 180);
}
var r = s2.getRange(5, 2, 180, 3);
r.sort([{ column: 3, ascending: false }, { column:2, ascending: false}]);
}
Aucun commentaire:
Enregistrer un commentaire