计算具有相同背景色的单元格列表

时间:2020-03-05 18:49:25  来源:igfitidea点击:

每个单元格包含一些文本和背景色。所以我有一些蓝色的单元格和一些红色的单元格。我用什么功能来计算红细胞的数量?

我已经尝试了`= COUNTIF(D3:D9,CELL(" color",D3)))没有成功(其中D3是红色的)。

解决方案

回答

Excel无法使用其内置函数来收集该属性。如果我们愿意使用某些VB,请在此处回答所有与颜色有关的问题:

http://www.cpearson.com/excel/colors.aspx

站点示例:

The SumColor function is a color-based
  analog of both the SUM and SUMIF
  function. It allows you to specify
  separate ranges for the range whose
  color indexes are to be examined and
  the range of cells whose values are to
  be summed. If these two ranges are the
  same, the function sums the cells
  whose color matches the specified
  value. For example, the following
  formula sums the values in B11:B17
  whose fill color is red.
  
  =SUMCOLOR(B11:B17,B11:B17,3,FALSE)

回答

如果单元格的颜色为负值,则工作表公式" = CELL(" color",D3)`将返回1"(否则将返回" 0")。

我们可以使用一些VBA解决此问题。将此插入到VBA代码模块中:

Function CellColor(xlRange As Excel.Range)
    CellColor = xlRange.Cells(1, 1).Interior.ColorIndex
End Function

然后使用函数= CellColor(D3)来显示D3的.ColorIndex。