Was wondering if anyone can help.
I currently have two scripts that I need to combine (to work on single spreadsheet) the first moves a completed row to new sheet;
function onEdit(event) {
// assumes source data in sheet named Current
// target sheet of move to named Completed
// test column with yes/no is col V
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "Current" && r.getColumn() == 24 && r.getValue() == "Yes") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Complete");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
}
and the second auto-sorts rows based on a value;
function onEdit(event){
var sheet = event.source.getActiveSheet();
var editedCell = sheet.getActiveCell();
var columnToSortBy = 14;
var tableRange = "A3:X150"; // What to sort.
if(editedCell.getColumn() == columnToSortBy){
var range = sheet.getRange(tableRange);
range.sort( { column : columnToSortBy, ascending: true } );
}
}
In an attempt to combine the two I've come up with this....
function onEdit(event) {
myFunction1(event);
myFunction2();
}
function myFunction1(event) {
// assumes source data in sheet named Current
// target sheet of move to named Completed
// test column with yes/no is col V
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "Current" && r.getColumn() == 24 && r.getValue() == "Yes") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Complete");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
function myFunction2() {
var sheet = event.source.getActiveSheet();
var editedCell = sheet.getActiveCell();
var columnToSortBy = 14;
var tableRange = "A3:X150"; // What to sort.
if(editedCell.getColumn() == columnToSortBy){
var range = sheet.getRange(tableRange);
range.sort( { column : columnToSortBy, ascending: true } );
}
}
}
The first script works but the second doesn't (won't auto-sort), can anyone tell me where I'm going wrong?
Link to spreadsheet here;