So, I'm not much of a coder to be honest, but I've managed to fumble my way through counting cell background colour, but struggling to get it to work for counting cells where the font is bold. I've detailed my function below, which counts only 6 cells with a bold font style, but there is 13 cells with a bold font style.
function countboldcells() {
var book = SpreadsheetApp.getActiveSpreadsheet();
var sheet = book.getActiveSheet();
var range_input = sheet.getRange("E2:S7");
var range_output = sheet.getRange("G14");
var cell_styles = range_input.getFontStyle();
var count = 0;
for(var r = 0; r < cell_styles.length; r++) {
for(var c = 0; c < cell_styles[0].length; c++) {
if(cell_styles.isBold = true) {
count = count + 1;
}
}
range_output.setValue(count);
}
}
getFontWeights() is the method that will return
bold
or not. Then the easy way to count them would be to flatten the array, filter all of the"bold"
elements and get the length of the filtered listYour if statement needs to have 3 "=" inside the parentheses
if(cell_styles.isBold === true)
Here is your code with corrections. Explanations are in the comments.