0
votes

I am new in Google Sheets. I am trying to make a spreadsheet on my company. It will move the whole row to another sheet when I click on checkbox. I wrote this code but it sometimes works and sometimes doesn't. Would anyone help me?

Here's the code

function onEdit(e) {
  const src = e.source.getActiveSheet();
  const r = e.range;
  if (src.getName() != "Teklifler" || r.columnStart != 11 || r.rowStart == 1) return;
  const dest = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Onaylanan");
  src.getRange(r.rowStart,1,1,15).moveTo(dest.getRange(dest.getLastRow()+1,1,1,15));
  src.deleteRow(r.rowStart);
    if (src.getName() != "Onaylanan" || r.columnStart != 15 || r.rowStart == 1) return;
  const desti = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Tamamlanan");
  src.getRange(r.rowStart,1,1,15).moveTo(desti.getRange(desti.getLastRow()+1,1,1,15));
  src.deleteRow(r.rowStart);

}

Here's the spreadsheet

https://docs.google.com/spreadsheets/d/1CxWCSNivWhXTQSpqlriMjapg1NssSfSEvbm8-Ay_a3A/edit?usp=sharing

Thanks for helping

1
Please explain what you're trying to do.Cooper

1 Answers

0
votes

I think you want to move the row if you check a checkbox of

  • "Onaylandı" column in "Teklifler" sheet

  • "Tamamlandı" column in "Onaylanan" sheet.

Try this.

function onEdit(e) {
  const src = SpreadsheetApp.getActiveSheet();
  const r = e.range;

  if (src.getName() == "Teklifler" && r.columnStart == 11 && r.isChecked()) {
    const dest = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Onaylanan");
    src.getRange(r.rowStart, 1, 1, 15).moveTo(dest.getRange(dest.getLastRow() + 1, 1, 1, 15));
    src.deleteRow(r.rowStart);
  }
  
  if (src.getName() == "Onaylanan" && r.columnStart == 15 && r.isChecked()) {
    const dest2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Tamamlanan");
    src.getRange(r.rowStart, 1, 1, 15).moveTo(dest2.getRange(dest2.getLastRow() + 1, 1, 1, 15));
    src.deleteRow(r.rowStart);
  }

}