Excel汇总超出范围的行数,符合多个条件

时间:2014-05-19 08:11:05

标签: excel colors excel-formula array-formulas

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

就目前而言,我尝试在Countifs中使用色彩功能,但它们似乎给出了错误的答案。有什么建议吗?

3 个答案:

答案 0 :(得分:1)

直接使用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

你需要知道颜色......使用功能:

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合作。例如:

enter image description here

使用名称之前定义的

,您可以创建一个列:

=IF(color>0;1;0)

和一个简单的:

=SUM(K5:K16)

以黄色单元格编号。
如果不进行重新计算(F9),请不要立即(也是VBA)...

答案 1 :(得分:1)

...重启
对于两种颜色的检查,对于我的功能,您有:

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(...)和(...)部分代码加上颜色的一部分...
在你的函数中我不理解这个部分SUM / Count ...

答案 2 :(得分:0)

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