I am changing the background color of rows and cells in a google sheet with a script. Right now I loop through rows and cells and perform the color changes. This is extremely slow. I know the best practice is to change the colors all at once. I am having trouble finding out how to store my cell range in an array and then perform a function again that range.
In the example here I'm trying to set every other row to white or grey if it is an odd or even row.
I have created a script I think would work but it fails.
function setRowColors() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var range = sheet.getDataRange();
var oddrange=[];
var evenrange=[];
for (var i = range.getRow()+7; i < range.getLastRow(); i++) {
var rowRow = i +1;
var rowRange = range.offset(i, 0, 1);
if (i % 2 == 0) {
oddrange.push(rowRange);
} else {
evenrange.push(rowRange);
}
}
oddrange.setBackgroundColors("#ffffff");
evenrange.setBackgroundColors("#efefef");
}
When I run this code I get this error "Cannot find function setBackgroundColors in object "