This Script is not working on below file
I use this script to move row to another sheet when value in column 21 =Delivered
i'm not a programer I try to understand how the script work and embedding code in other code
so if you can help me to rewrite this script to be faster and working better
Thanks in advance
/*
**** Move a row onEdit determined by a specific Cell value***
*/
// Names of sheets
var destinationSheet = "Collate"
/* col: the column to watch,
* changeVal: what value you want to change,
* del: do you want to delete after the change?
*/
var check = {
"col":17,
"changeVal": "DELIVERED",
"del": true ,
};
/* What you want to paste into the other sheet.
* start: start column
* cols: how many columns you want to copy
*/
var pasteRange = {
"start": 1,
"cols": 35
};
function onEdit(e) {
var sheets = ['FOOD', 'PET', 'KIND', 'Campbell', 'Other Clients']
for (var i = 0; i < sheets.length; i++) {
var sheetName = sheets[i]
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
if (sheet != null) {
if(sheet.getName() === sheets){
//Get active cell
var cell = sheet.getActiveCell();
var cellCol = cell.getColumn();
var cellRow = cell.getRow();
if(cellCol === check.col){
if(cell.getValue() === check.changeVal){
//Select the range you want to export
var exportRange = sheet.getRange(cellRow,pasteRange.start,1,pasteRange.cols);
//Select the past destination
var pasteDestination = ss.getSheetByName(destinationSheet);
var pasteEmptyBottomRow = pasteDestination.getLastRow() + 1;
//Copy the row to the new destination
exportRange.copyTo(pasteDestination.getRange(pasteEmptyBottomRow,1),
SpreadsheetApp.CopyPasteType.PASTE_VALUES);
//If delete is true delete after copying
if(check.del){
sheet.deleteRow(cellRow);
};
};
};
};
};
};
};