Excel对超过范围的行数进行求和,以符合多个条件

我正在寻找一种方法来计算我的范围(超过两列运行)有多less行符合的标准,行中的一个单元格具有特定的背景颜色,而同一行中的另一个单元格具有不同的具体背景颜色。

事实certificate,我已经尝试使用Countifs内的颜色function,但他们似乎给出了错误的答案。 有什么build议么?

重新开始…
为了检查两种颜色,对于我的function你有:

Public Function CountColor(Sel As Range, Col As Long, Col1 As Long) As Long Application.Volatile Dim i As Long i = 0 For Each xx In Sel If (xx.Interior.Color = Col) And (xx.Offset(0, 1).Interior.Color = Col1) Then i = i + 1 Next CountColor = i End Function 

如果你想引用一个单元格的颜色:

 Public Function CountColorR(Sel As Range, ColR As Range, ColR1 As Range) As Long Application.Volatile Dim i, Col, Col1 As Long Col = ColR.Interior.Color Col1 = ColR1.Interior.Color i = 0 For Each xx In Sel If (xx.Interior.Color = Col) And (xx.Offset(0, 1).Interior.Color = Col1) Then i = i + 1 Next CountColorR = i End Function 

在你的函数中,你需要添加if(…)和(…)代码部分以及颜色部分
在你的function,我不明白与SUM /计数部分…

直接与EXCEL函数,我认为这是不可能的,因为你没有一个函数,返回内部颜色。
使用VBA(模块内):

 Public Function CountColor(Sel As Range, Col As Long) As Long Dim i As Long i = 0 For Each xx In Sel If xx.Interior.Color = Col Then i = i + 1 Next CountColor = i End Function 

你需要知道颜色…使用function:

 Public Function InnerColor(Sel As Range) As Long InnerColor = Sel.Interior.Color End Function 

使用NAMES:定义名称 – >颜色:

 =GET.CELL(63;OFFSET(INDIRECT("RC";FALSE);0;-1)) 

你可以有一个间接的参考。 不要与Countif一起工作。 在如下情况下:

在这里输入图像说明

名称之前定义,您可以创build一个列:

 =IF(color>0;1;0) 

和一个简单的:

 =SUM(K5:K16) 

有黄色的细胞数量。
如果不重新计算(F9),则不要立即(也包括VBA)工作…

 Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean) Dim rCell As Range Dim lCol As Long Dim vResult lCol = rColor.Interior.ColorIndex If Count = True Then For Each rCell In rRange If rCell.Interior.ColorIndex = lCol Then vResult = WorksheetFunction.Count(rCell) + vResult End If Next rCell Else For Each rCell In rRange If rCell.Interior.ColorIndex = lCol Then vResult = 1 + vResult End If Next rCell End If ColorFunction = vResult End Function