P
P
PiShim2021-06-04 05:39:17
Google Sheets
PiShim, 2021-06-04 05:39:17

How to change the condition in the script to delete a row by condition?

There is a script that deletes the selected line with a checkbox when the data changes from False to True in the first column A. That is, when the checkbox is selected in cell A1, row 1 is deleted, when cell A2 is selected, row 2 is deleted, etc. Now the essence of the problem, there is a script in which changing the data in column A deletes the row. Help modify the script so that instead of column A, replace it with column W.

function onEdit(e) {
  Logger.log(e);
  Logger.log(e.value);
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheetS = ss.getSheets()[2];
  var sheetD = ss.getSheets()[3];
  var lastColumn = sheetS.getLastColumn();
  var lastRow = sheetD.getLastRow();
  if (e.value === 1) {
    var range = e.range;
    var row = range.getRow();
    Logger.log(row);
    var val = sheetS.getRange(row, 1, 1, lastColumn).getValues();
    sheetD.getRange(lastRow + 1, 1, 1, lastColumn).setValues(val);
    sheetS.deleteRow(row);
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2021-06-04
@PiShim

The code is pretty weird and hard to tie to something, but the simplest is

function onEdit(e) {
  Logger.log(e);
  Logger.log(e.value);
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheetS = ss.getSheets()[2];
  var sheetD = ss.getSheets()[3];
  var lastColumn = sheetS.getLastColumn();
  var lastRow = sheetD.getLastRow();
  if (e.range.getColumn() == 23 && e.value == 1) {
    var range = e.range;
    var row = range.getRow();
    Logger.log(row);
    var val = sheetS.getRange(row, 1, 1, lastColumn).getValues();
    sheetD.getRange(lastRow + 1, 1, 1, lastColumn).setValues(val);
    sheetS.deleteRow(row);
  }
}

Cm.if (e.range.getColumn() == 23 && e.value == 1) {

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question