In a Google Sheets spreadsheet, I have some cells green and red-colored. I want a cell having the count of those green/red colored cells.
Is there a formula to do this thing or any custom code for this?
In a Google Sheets spreadsheet, I have some cells green and red-colored. I want a cell having the count of those green/red colored cells.
Is there a formula to do this thing or any custom code for this?
This Google Apps Script should get you started (see example spreadsheet):
function countRedBackgrounds() {
var COUNT_RED = 0;
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Cell colors");
var dataRange = sheet.getDataRange();
for (var i = 1; i<dataRange.getNumRows(); i++) {
for (var j = 1; j<dataRange.getNumColumns(); j++) {
if (dataRange.getCell(i,j).getBackground() == "#ff0000")
COUNT_RED++;
}
}
dataRange.getCell(1,1).setValue(COUNT_RED);
}