在Google电子表格中用相同的颜色计算单元格 [英] Count the cells with same color in google spreadsheet

查看:194
本文介绍了在Google电子表格中用相同的颜色计算单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图计算具有相同背景颜色的单元格数量,并将结果放在其他单元格中,并在Google应用脚本中添加脚本,但我无法做到这一点。

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 next script but not work and I don't know which is the problem:

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()[0];
 var color = "#58FA58";
 var count = 0;

 for( var i in cell_colors )
  if( cell_colors[i] == color ){
    range_output.setValue(++count);
  }
  else {
    return count; 
  }
 }  


推荐答案

如果您不想使用 Google表格电源工具

Easy solution if you don't want to code manually using Google Sheets Power Tools:


  1. 通过附加组件面板安装电动工具(附加组件 - >获取附加组件)

  2. 从电动工具侧栏点击Σ按钮并在该菜单中点击按颜色求和菜单项

  3. 选择带有颜色标记的图案单元格您想要搜索

  4. 为要计数的单元格选择源范围
  5. 使用函数应设置为COUNTA

  6. 按下插入功能即可完成:)
  1. Install Power Tools through the Add-ons panel (Add-ons -> Get add-ons)
  2. From the Power Tools sidebar click on the Σ button and within that menu click on the "Sum by Color" menu item
  3. Select the "Pattern cell" with the color markup you want to search for
  4. Select the "Source range" for the cells you want to count
  5. Use function should be set to "COUNTA"
  6. Press "Insert function" and you're done :)

这篇关于在Google电子表格中用相同的颜色计算单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆