D
D
DenniLa22017-11-29 18:04:06
Google Sheets
DenniLa2, 2017-11-29 18:04:06

How to calculate the sum of a range of cells of only a certain style in Google spreadsheets?

How to calculate the sum of a range of cells in Google spreadsheets, only of a certain style, for example, red or italic?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan, 2017-12-02
@Iv_and_S

scripts can get any cell formatting.
a function written in a script, then used as a regular function in a table.
some minimal example below.

function summRedColor() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  
  var range = sheet.getRange("H4:H6");
  var bgColors = range.getBackgrounds();
  var values = range.getValues();
  var allRedColorRangeValues = [];
  
  for (var i in bgColors) {
    if(bgColors[i] == "#ff0000"){
    allRedColorRangeValues.push(values[i]);
      Logger.log("красный цвет");
    }
    else{
    Logger.log("другой цвет");
    }
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question