1. 进入你的EXCEL文件,按 ALT + F11,进入VBA编辑状态
2. 插入 ---> 模块 , Insert ---> Module
3. 将以下VBA代码贴入
4. 使用该自定义SumColor函数
第一个参数:基准字体颜色单元格,第二个参数就是汇总的范围。
例如:C1-C10,红色的字体求和,
公式 = sumcolor( 选一个任意红色的单元格,C1:C10)
Function SumColor(rColor As Range, rSumRange As Range)
'Sums cells based on a specified Font color.
'以字体颜色求和
Dim rCell As Range
Dim iCol As Integer
Dim vResult
iCol = rColor.Font.ColorIndex
For Each rCell In rSumRange
If rCell.Font.ColorIndex = iCol Then
vResult = WorksheetFunction.Sum(rCell) + vResult
End If
Next rCell
SumColor = vResult
End Function
温馨提示:答案为网友推荐,仅供参考