1

I have written some scripts in google app script to move that specific row on the basis of particular value of a cell. But surprisingly some row are missing automatically. These rows are vanished & found no where in sheet. Please help to find why data are missing automatically. Code that is running to do so is written below.

  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)});```
Ankur
  • 11
  • 1
  • It seems that your script moves the rows that the column "V" has `Cancelled` to the destination sheet. And the moved rows are deleted. So I cannot understand `But surprisingly some row are missing automatically. These rows are vanished & found no where in sheet.`. I apologize for this. In order to correctly understand your current issue, can you provide the sample Spreadsheet for replicating your issue? – Tanaike Nov 29 '21 at 07:32

1 Answers1

0
function myfunck() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Delhi Calls Amit");
  const vs = sh.getRange(1, 22, sh.getLastRow(), 1).getValues().filter(e => e[0] == "Cancelled");
  const tsh = ss.getSheetByName("Happy Calling Delhi");
  tsh.getRange(tsh.getLastRow() + 1,1,vs.length,vs[0].length).setValues(vs);
}
Cooper
  • 59,616
  • 6
  • 23
  • 54