【发布时间】:2016-08-16 03:21:11
【问题描述】:
我有以下宏 CountCellsByColor (ORIGNAL BELOW) 但是我想修改它,以便它按颜色和单元格的特定文本来计算单元格。
例如:该范围有 5 个不同的名称,它们都用不同的颜色着色。我希望宏只计算与参考单元格具有相同名称和颜色的单元格。即“弗雷德”“黄色”细胞的数量
原始公式如下:
Function CountCellsByColor(rData As Range, cellRefColor As Range) As Long
Dim indRefColor As Long
Dim cellCurrent As Range
Dim cntRes As Long
Application.Volatile
cntRes = 0
indRefColor = cellRefColor.Cells(1, 1).Interior.Color
For Each cellCurrent In rData
If indRefColor = cellCurrent.Interior.Color Then
cntRes = cntRes + 1
End If
Next cellCurrent
CountCellsByColor = cntRes
End Function
【问题讨论】:
-
感谢杰里米,您的原始评论有效,即 - 如果 indRefColor = cellCurrent.Interior.Color 和 cellCurrent.Value = searchtext 然后 - 我只是没有输入它最初写的。非常感谢您的帮助。真的很感激