美文网首页
Excel对特定区域按颜色求和 、计数

Excel对特定区域按颜色求和 、计数

作者: 麦地蓝天 | 来源:发表于2016-02-01 00:09 被阅读388次

    对一些特殊的数据标注了颜色,想要快速求出这些区域的和,有两种方法:

    Function SumByColor(Ref_color As Range,Sum_range As Range)

    Application.Volatile

    Dim iCol As Integer

    Dim rCell As Range

    iCol = Ref_color.Interior.ColorIndex

    For Each rCell In Sum_range

    If iCol = rCell.Interior.ColorIndex Then

    SumByColor = SumByColor + rCell.Value

    End If

    Next rCell

    End Function

    Function CountByColor(Ref_color As Range, CountRange As Range)

    Application.Volatile

    Dim iCol As Integer

    Dim rCell As Range

    iCol = Ref_color.Interior.ColorIndex

    For Each rCell In CountRange

    If iCol = rCell.Interior.ColorIndex Then

    CountByColor = CountByColor + 1

    End If

    Next rCell

    End Function

    Excel对特定区域按颜色求和 、计数

    相关文章

      网友评论

          本文标题:Excel对特定区域按颜色求和 、计数

          本文链接:https://www.haomeiwen.com/subject/ocjskttx.html