既然每个单元格都是 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