I am trying to produce a visual rota for my restaurant using Google Sheets. I need to count the background color of a row in order to get a figure for the number of half hour periods worked that day.
Here is a link to the google sheet:
https://docs.google.com/spreadsheets/d/19IEDGZypi3nVt55-OayvPo__pbV0sTuRQ3wCJZ1Mhck/edit?usp=sharing
And the script that I am using:
function countBG(range, colorref) {
var sheet = SpreadsheetApp.getActiveSheet();
var color = sheet.getRange(colorref).getBackground();
var range = sheet.getRange(range);
var rangeVal = range.getValues();
var count = 0;
var allColors = range.getBackgrounds();
for (var i = 0; i < allColors.length; i++) {
for (var j = 0; j < allColors[0].length; j++) {
if (allColors[i][j] == color) count += 1;
};
};
return count;
}
I find that the script works the first time it's run, but after that it gives an error:
Range not found (line 4, file "Code")
Would appreciate any help in getting this working, I'm new at Google Sheets and scripting so possibly missing something obvious.
Thanks,
DB.