Just a note: I am not very versed in coding and brand new to google script.
I am trying test for background color within a script. Specifically, I will have an array of names stored into a named range and want to count how many cells are set to green.
So far I have the following but receive an error: TypeError: Cannot set property "0.0" of undefined to "#00ff00"
function testCount(range) {
var ranges = SpreadsheetApp.getActiveSpreadsheet().getRangeByName("testrange");
var names = SpreadsheetApp.getActiveSpreadsheet().getRangeByName("testrange").getValues();
var NumColumns = ranges.getNumColumns();
var NumRows = ranges.getNumRows();
var c = 0;
for (var i = 0; i<NumColumns; i++){
for (var j = 0; j<NumRows; j++){
if (ranges.getBackgrounds()[i][j] ="#00ff00"){
c++;
}else{
c=c;
}
}
}
return c;
I grabbed the value for green when I tried the following for a cell that was colored
return ranges.getBackgrounds()[0][1];