I have some issue where i had written a script that on the basis of a particular value of a row it should move to the specific sheet but dramatically it disappear simultaneously sometimes it work good & sometimes it vanished that row & can’t find anywhere in the spreadsheet where it had gone no one knows & even in some cases it automatically disappear or move the row by itself even if it is not defined to do so. Function is written below please help to rectify it.
function onEdit(e)
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Delhi Calls Asha");
var values = sheet.getRange(1, 4, sheet.getLastRow(), 1).getValues();
var moveRows = values.reduce(function(ar, e, i) {
if (e[0] == "LG") ar.push(i + 1);
return ar;
}, []);
var targetSheet = ss.getSheetByName("DELHI Calls Amit");
moveRows.forEach(function(e) {
sheet.getRange(e, 1, 1, sheet.getLastColumn()).moveTo(targetSheet.getRange(targetSheet.getLastRow() + 1, 1));
});
moveRows.reverse().forEach(function(e) {sheet.deleteRow(e)});
}
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Delhi Calls Amit");
var values = sheet.getRange(1, 22, sheet.getLastRow(), 1).getValues();
var moveRows = values.reduce(function(ar, e, i) {
if (e[0] == "Cancelled") ar.push(i + 1);
return ar;
}, []);
var targetSheet = ss.getSheetByName("Happy Calling Delhi");
moveRows.forEach(function(e) {
sheet.getRange(e, 1, 1, sheet.getLastColumn()).moveTo(targetSheet.getRange(targetSheet.getLastRow() + 1, 1));
});
moveRows.reverse().forEach(function(e) {sheet.deleteRow(e)});
}
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Delhi Calls Amit");
var values = sheet.getRange(1, 22, sheet.getLastRow(), 1).getValues();
var moveRows = values.reduce(function(ar, e, i) {
if (e[0] == "Closed") ar.push(i + 1);
return ar;
}, []);
var targetSheet = ss.getSheetByName("Happy Calling Delhi");
moveRows.forEach(function(e) {
sheet.getRange(e, 1, 1, sheet.getLastColumn()).moveTo(targetSheet.getRange(targetSheet.getLastRow() + 1, 1));
});
moveRows.reverse().forEach(function(e) {sheet.deleteRow(e)});
}
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Delhi Calls Asha");
var values = sheet.getRange(1, 22, sheet.getLastRow(), 1).getValues();
var moveRows = values.reduce(function(ar, e, i) {
if (e[0] == "Cancelled") ar.push(i + 1);
return ar;
}, []);
var targetSheet = ss.getSheetByName("Happy Calling Delhi");
moveRows.forEach(function(e) {
sheet.getRange(e, 1, 1, sheet.getLastColumn()).moveTo(targetSheet.getRange(targetSheet.getLastRow() + 1, 1));
});
moveRows.reverse().forEach(function(e) {sheet.deleteRow(e)});
}
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet4 = ss.getSheetByName("Delhi Calls Asha");
var values4 = sheet4.getRange(1, 22, sheet4.getLastRow(), 1).getValues();
var moveRows4 = values4.reduce(function(ar, e, i) {
if (e[0] == "Closed") ar.push(i + 1);
return ar;
}, []);
var targetSheet4 = ss.getSheetByName("Happy Calling Delhi");
moveRows4.forEach(function(e) {
sheet4.getRange(e, 1, 1, sheet4.getLastColumn()).moveTo(targetSheet4.getRange(targetSheet4.getLastRow() + 1, 1));
});
moveRows4.reverse().forEach(function(e) {sheet4.deleteRow(e)});
}
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet5 = ss.getSheetByName("MUMBAI Calls");
var values5 = sheet5.getRange(1, 22, sheet5.getLastRow(), 1).getValues();
var moveRows5 = values5.reduce(function(ar, e, i) {
if (e[0] == "Cancelled") ar.push(i + 1);
return ar;
}, []);
var targetSheet5 = ss.getSheetByName("Happy Calling Mumbai");
moveRows5.forEach(function(e) {
sheet5.getRange(e, 1, 1, sheet5.getLastColumn()).moveTo(targetSheet5.getRange(targetSheet5.getLastRow() + 1, 1));
});
moveRows5.reverse().forEach(function(e) {sheet5.deleteRow(e)});
}
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet6 = ss.getSheetByName("MUMBAI Calls");
var values6 = sheet6.getRange(1, 22, sheet6.getLastRow(), 1).getValues();
var moveRows6 = values6.reduce(function(ar, e, i) {
if (e[0] == "Closed") ar.push(i + 1);
return ar;
}, []);
var targetSheet6 = ss.getSheetByName("Happy Calling Mumbai");
moveRows6.forEach(function(e) {
sheet6.getRange(e, 1, 1, sheet6.getLastColumn()).moveTo(targetSheet6.getRange(targetSheet6.getLastRow() + 1, 1));
});
moveRows6.reverse().forEach(function(e) {sheet6.deleteRow(e)});
}
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet7 = ss.getSheetByName("Happy Calling Delhi");
var values7 = sheet7.getRange(1, 31, sheet7.getLastRow(), 1).getValues();
var moveRows7 = values7.reduce(function(ar, e, i) {
if (e[0] == "satisfied") ar.push(i + 1);
return ar;
}, []);
var targetSheet7 = ss.getSheetByName("Main Sheet Mix");
moveRows7.forEach(function(e) {
sheet7.getRange(e, 1, 1, sheet7.getLastColumn()).moveTo(targetSheet7.getRange(targetSheet7.getLastRow() + 1, 1));
});
moveRows7.reverse().forEach(function(e) {sheet7.deleteRow(e)});
}
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet8 = ss.getSheetByName("Happy Calling Delhi");
var values8 = sheet8.getRange(1, 31, sheet8.getLastRow(), 1).getValues();
var moveRows8 = values8.reduce(function(ar, e, i) {
if (e[0] == "SATISFIED") ar.push(i + 1);
return ar;
}, []);
var targetSheet8 = ss.getSheetByName("Main Sheet Mix");
moveRows8.forEach(function(e) {
sheet8.getRange(e, 1, 1, sheet8.getLastColumn()).moveTo(targetSheet8.getRange(targetSheet8.getLastRow() + 1, 1));
});
moveRows8.reverse().forEach(function(e) {sheet8.deleteRow(e)});
}
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet9 = ss.getSheetByName("Happy Calling Mumbai");
var values9 = sheet9.getRange(1, 31, sheet9.getLastRow(), 1).getValues();
var moveRows9 = values9.reduce(function(ar, e, i) {
if (e[0] == "satisfied") ar.push(i + 1);
return ar;
}, []);
var targetSheet9 = ss.getSheetByName("Main Sheet Mumbai");
moveRows9.forEach(function(e) {
sheet9.getRange(e, 1, 1, sheet9.getLastColumn()).moveTo(targetSheet9.getRange(targetSheet9.getLastRow() + 1, 1));
});
moveRows9.reverse().forEach(function(e) {sheet9.deleteRow(e)});
}
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet10 = ss.getSheetByName("Main Sheet Mumbai");
var values10 = sheet10.getRange(1, 58, sheet10.getLastRow(), 1).getValues();
var moveRows10 = values10.reduce(function(ar, e, i) {
if (e[0] == "Reopen") ar.push(i + 1);
return ar;
}, []);
var targetSheet10 = ss.getSheetByName("MUMBAI Calls");
moveRows10.forEach(function(e) {
sheet10.getRange(e, 1, 1, sheet10.getLastColumn()).moveTo(targetSheet10.getRange(targetSheet10.getLastRow() + 1, 1));
});
moveRows10.reverse().forEach(function(e) {sheet10.deleteRow(e)});
}
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet11 = ss.getSheetByName("Happy Calling Mumbai");
var values11 = sheet11.getRange(1, 31, sheet11.getLastRow(), 1).getValues();
var moveRows11 = values11.reduce(function(ar, e, i) {
if (e[0] == "SATISFIED") ar.push(i + 1);
return ar;
}, []);
var targetSheet11 = ss.getSheetByName("Main Sheet Mumbai");
moveRows11.forEach(function(e) {
sheet11.getRange(e, 1, 1, sheet11.getLastColumn()).moveTo(targetSheet11.getRange(targetSheet11.getLastRow() + 1, 1));
});
moveRows11.reverse().forEach(function(e) {sheet11.deleteRow(e)});
}
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet12 = ss.getSheetByName("Main Sheet Mix");
var values12 = sheet12.getRange(1, 58, sheet12.getLastRow(), 1).getValues();
var moveRows12 = values12.reduce(function(ar, e, i) {
if (e[0] == "Reopen") ar.push(i + 1);
return ar;
}, []);
var targetSheet12 = ss.getSheetByName("DELHI Calls Asha");
moveRows12.forEach(function(e) {
sheet12.getRange(e, 1, 1, sheet12.getLastColumn()).moveTo(targetSheet12.getRange(targetSheet12.getLastRow() + 1, 1));
});
moveRows12.reverse().forEach(function(e) {sheet12.deleteRow(e)});
}