1
votes

I've got a script that moves a row from one tab "COMMUNICATIONS" to another tab "ARCHIVE" when a cell checkbox (column AE) is true but it's only working well with the row AE2 and it's not working when I check AE3 or AE6.

function onEdit() {

  var sheetNameToWatch = "COMMUNICATIONS";
  var sheetNameToMoveTheRowTo = "ARCHIVE";

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = SpreadsheetApp.getActiveSheet();
  var range = sheet.getActiveCell();

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet1 = ss.getSheetByName(sheetNameToWatch);
  var sheet2 = ss.getSheetByName(sheetNameToMoveTheRowTo);


  var cell1 = sheet1.getRange("AE2:AE1000");

  var x= cell1.getValue();

  Logger.log("a",x);


  if(cell1.getValue()== false) {

  Logger.log("box not checked");

    sheet1.showSheet();


  } else if (cell1.getValue() == true) {

    var targetSheet = ss.getSheetByName(sheetNameToMoveTheRowTo);

    var targetRange = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);

    sheet.getRange(range.getRow(), 1, 1, 
    sheet.getLastColumn()).moveTo(targetRange);

    sheet.deleteRow(range.getRow());

  }
}
1

1 Answers

1
votes

you can try this code. I Tested it on one of my sheets and it worked fine.

   function onEdit(event) {
  // assumes source data in sheet named Active
  // target sheet of move to named Found 
  // test column with yes/no is col 13 or M
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = event.source.getActiveSheet();
  var r = event.source.getActiveRange();

  if(s.getName() == "COMMUNICATIONS" && r.getColumn() == 13 && r.getValue() == true) {
    var row = r.getRow();
    var numColumns = s.getLastColumn();
    var targetSheet = ss.getSheetByName("ARCHIVE");
    var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
    s.getRange(row, 1, 1, numColumns).moveTo(target);
    s.deleteRow(row);
  }

}