'How to go over a 2 columns and set the colour of a cell under a condition

Im trying to go over 2 column and set the colour of them into red if they are not equal to specefic string, but its not working with me.

Here is my code.

function setCellColors() {
  //Get the sheet you want to work with. 
   const thisSheet = SpreadsheetApp.openByUrl(THIS).getSheetByName('Project');
   var range = thisSheet.getRange("V3:W").getValues();
   var newData = range;
   for (var i in newData) {
  if(newData!== "There is no NCR" && newData !=="N/A" && newData!=="There is no Reason Codes"){
  newData.setBackground("red");
  } 
  }
}

I,m keep getting this error "TypeError: newData.setBackground is not a function" which I think because newData ia=s an array but how would I change it to string in that case, and is the rest of the code right?

If you need more information please let me know

Thank you.



Solution 1:[1]

Set selected backgrounds to red

function setCellColors() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getActiveSheet(Project);
  const tA = ["There is no NCR", "N/A", "There is no Reason Codes"];
  const vs = sh.getRange(3, 22, sh.getLastRow() - 2, 1).getValues();
  const newData = vs;
  vs.forEach((r, i) => {
    if (!~tA.indexOf(r[0])) {
      sh.getRange(i + 3, 22).setBackground("red");
    }
  });
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cooper