嗨,我正在尝试使用VBA在excel中添加sumbycolor公式。但是,当使用条件格式对某些单元格进行着色时,该代码不起作用。否则它正在工作。有人可以帮忙吗?谢谢
Function SumByColor(CellColor As Range, rRange As Range)
Dim cSum As Long
Dim ColIndex As Integer
ColIndex = CellColor.Interior.ColorIndex
For Each cl In rRange
If cl.Interior.ColorIndex = ColIndex Then
cSum = WorksheetFunction.SUM(cl, cSum)
End If
Next cl
SumByColor = cSum
End Function
Function ColorIndex(CellColor As Range)
ColorIndex = CellColor.Interior.ColorIndex
End Function