Count the cells with same color in google spreadsheet

后端 未结 5 460
夕颜
夕颜 2021-01-03 21:15

I\'m trying count the number of cells with the same background color and put the result in other cell with a script in google apps script, but I can\'t do it. I have the nex

5条回答
  •  失恋的感觉
    2021-01-03 21:40

    here is a working version :

    function countbackgrounds() {
     var book = SpreadsheetApp.getActiveSpreadsheet();
     var range_input = book.getRange("B3:B4");
     var range_output = book.getRange("B6");
     var cell_colors = range_input.getBackgroundColors();
     var color = "#58FA58";
     var count = 0;
    
     for( var i in cell_colors ){
     Logger.log(cell_colors[i][0])
      if( cell_colors[i][0] == color ){ ++count }
      }
    range_output.setValue(count);
     }  
    

提交回复
热议问题