Those answers were great, but for me it breaks when pass the Z column (column number 26 to number 27, when we have two letters).
Added a small change to fix that (on the italic version)
/**
* Sums cell values in a range if they are italic. The use of startcol and startrow
* is to enable the formula to be copied / dragged relatively in the spreadsheet.
*
* @param {Array.Array} range Values of the desired range
* @param {int} startcol The column of the range
* @param {int} startrow The first row of the range
*
* @return {int} Sum of all cell values matching the condition
* @customfunction
*/
function sumIfItalic(range, startcol, startrow){
// convert from int to ALPHANUMERIC
// - thanks to Daniel at http://stackoverflow.com/a/3145054/2828136
var secondColChar = parseInt(startcol / 27); //26 is the number of col Z, 26 letters, works for only for two char
var start_col_id = ""
var end_col_id = ""
if(secondColChar > 0) {
start_col_id += String.fromCharCode(64 + (secondColChar));
end_col_id += String.fromCharCode(64 + secondColChar + range[0].length -1);
}
start_col_id += String.fromCharCode(64 + (startcol % 27 + (secondColChar * 1)) );
end_col_id += String.fromCharCode(64 + (startcol % 27) + (secondColChar * 1) + range[0].length -1);
var endrow = startrow + range.length - 1
// build the range string, then get the font styles
var range_string = start_col_id + startrow + ":" + end_col_id + endrow
var ss = SpreadsheetApp.getActiveSpreadsheet();
var getStyles = ss.getRange(range_string).getFontStyles();
var x = 0;
var value;
for(var i = 0; i < range.length; i++) {
for(var j = 0; j < range[0].length; j++) {
if(getStyles[i][j].toString() == "italic") {
value = range[i][j];
if (!isNaN(value)){
x += value;
}```
}
}
}
return x*1;
}
tested only in my case, though...