I am trying to do a script to iterate over a column in a sheet, compare the cell value with another cells and changing the background color when they are equal.
I am new both to JS and google scripting, so I am having problems with a for loop, as I always get a "Cell reference out of range" error. Here is my code so far:
function onOpen()
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Exibicao");
var range = sheet.getDataRange();
var rows = range.getNumRows();
for(var i = 0; i <= rows; i++)
{
var cell = range.getCell(i, 13);
var option1 = cell.offset(0, -3);
var option2 = cell.offset(0, -2);
var option3 = cell.offset(0, -1);
if(option1.getValue() == cell.getValue()){
option1.setBackground("#b6d7a8");
}else if(option2.getValue() == cell.getValue()){
option2.setBackground("#b6d7a8");
}else if(option3.getValue() == cell.getValue()){
option3.setBackground("#b6d7a8");
}
}
}