打开Excel,按alt+F11 开启宏模式
选择“插入”---》“模块”
Function sumcolor(rng1 As Range, rng2 As Range) As Single
Dim cell As Range
sumcolor = 0
For Each cell In rng1
If cell.font.Color = rng2.font.Color Then sumcolor = sumcolor + cell.value
Next cell
End Function
退出宏,在Excel中任意单元格输入:=sumColor(A1:A15,A4) ,其中A1:A15是计算单元格的范围,A4是指标红的单元格。
会将A1:A15范围内单元格的字体颜色和A4单元格颜色想比较。如果相同则会求和。