0

I want to write a google script that will delete all the cells in column 'N' if row 'R' has the text 'Rejected'. I have written this script but it deleting all the cells in Column 'N'. help me with my error or suggest a better script.

function clean0() {
  var app = SpreadsheetApp;
  var activeSheet = app.getActiveSpreadsheet().getSheetByName('Tasks');

  for (var i = 2; i < 100; i++) {
    var workingCell = activeSheet.getRange(i, 18).getValue();

    if (workingCell = '0') {
      activeSheet.getRange(i, 14).setValue("a");
    } else {

    }
  }
}
adiga
  • 34,372
  • 9
  • 61
  • 83

1 Answers1

0

As @VLAZ said, you have to use == or === instead of = to compare two values.

From Comparision operators:

console.log(1 == 1);
// expected output: true

console.log('1' == 1);
// expected output: true

console.log(1 === 1);
// expected output: true

console.log('1' === 1);
// expected output: false

In case of if (workingCell = '0', it always returns true as it's an assignement, not a comparision.

Jescanellas
  • 2,555
  • 2
  • 9
  • 20