Update a cell's value according to colored cells - Google Docs Spreadsheet

女生的网名这么多〃 提交于 2019-12-09 14:03:36

问题


In Google Docs spreadsheet, I have some cells green and red colored. I want a cell having the count of those green/red colored cells.

Can I have a formula to do this thing or any custome code for this?


回答1:


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);
}


来源:https://stackoverflow.com/questions/15923795/update-a-cells-value-according-to-colored-cells-google-docs-spreadsheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!