EXCEL高手进,求excel表格,按表格颜色统计表格的数量

有一个表格,里边每一个小格填充不同的颜色(有四种填充颜色),凡是填充颜色的小格里面的数是0.5,怎样统计出不同颜色的小格里边数据的总和,既红色格数据加起来是x蓝色是X.....

既然每个单元格都是 0.5,那可以先统计个数,再乘0.5就得数据总和了。

可以用下面的代码统计个数,前提是颜色是填充的,不是条件格式。

不能用 colorindex 作为查找条件。

Private Sub CommandButton1_Click()
Dim Ar(1 To 4, 1 To 1) As Long
Ar(1, 1) = FindColor(Cells, 52479) '橙色 Color
Ar(2, 1) = FindColor(Cells, RGB(255, 0, 0)) '红色 RGB
Ar(3, 1) = FindColor(Cells, vbGreen) '绿色
Ar(4, 1) = FindColor(Cells, 16711935) '紫红色

End Sub
Function FindColor(Rng As Range, MyColor As Long) As Long
Dim R As Range
Application.FindFormat.Clear
Application.FindFormat.Interior.Color = MyColor
Set R = Rng.Find("", SearchFormat:=True)
If R Is Nothing Then Exit Function
S = R.Address
Do
FindColor = FindColor + 1
Set R = Rng.Find("", After:=R, SearchFormat:=True)
Loop Until S = R.Address
End Function

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-04-24
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ss As Integer
ss = Target.Text
If ss > 0.5 Then
Target.Interior.Color = RGB(255, 100, 0)
end if

End Sub
相似回答