我想在状态跟踪器上使用以下函数"CountCcolor()“。我的意图是能够使用该函数在单个列中查找可见单元格的范围,以特定颜色高亮显示多少,比如绿色。
Function CountCcolor(range_data As Range, criteria As Range) As Long
Dim datax As Range
Dim xcolor As Long
' The next one-liner does not work. Without it, it selects visible and hidden cells. I only want it to select visible cells:
range_data = Selection.SpecialCells(xlCellTypeVisible).Select
xcolor = criteria.Interior.ColorIndex
For Each datax In range_data
If datax.Interior.ColorIndex = xcolor Then
CountCcolor = CountCcolor + 1
End If
Next datax
End Function谢谢你提前提供帮助!
发布于 2018-10-04 02:44:20
不要使用Interior.ColorIndex
相反,只需使用Interior.Color。我也曾被这件事困扰过一次。简而言之,ColorIndex代表的是颜色的味觉,而不是是独特的颜色。有关更多细节,请参见here
Function CountCcolor(range_data As Range, criteria as Range) As Long
Dim myRange As Range, myCell As Range, TempCount As Long
Set myRange = range_data.SpecialCells(xlCellTypeVisible)
For Each myCell In myRange
If myCell.Interior.Color = criteria.Interior.Color Then
TempCount = TempCount + 1
End If
Next myCell
CountCcolor = TempCount
End Functionhttps://stackoverflow.com/questions/52638119
复制相似问题