解决思路如下:
1、 首先把需要统计的单元格字体颜色设置成在整个区域中不曾使用的颜色;
2、 然后调用下面的函数进行统计;
3、 参数说明:Rng:需要统计的整个区域;Rng2:具有需要统计单元格一致的字体颜色的单元格;
4、 用vba编制的小函数如下:
Function SumByColor(Rng As Range, Rng2 As Range) As Double
Dim R As Range
Dim Total As Double
For Each R In Rng.Cells
If R.Font.Color = Rng2.Font.Color Then
Total = Total + R.Value
End If
Next R
SumByColor = Total
End Function
Function CountByColor(Rng As Range,Rng2 As Range) As Long
Dim R As Range
Dim Count As Long
For Each R In Rng.Cells
If R.Font.Color = Rng2.Font.Color Then
Count = Count + 1
End If
Next R
CountByColor = Count
End Function
5、 打开excel的VB代码编写环境;
6、 进入VB编程环境,插入模块;
7、 把上面的程序copy到下面位置:
8、 按照以下实例验证看看效果吧!
