有没有办法只统计正在显示的行?
此方法无效:
For Each TCell In CountRange.SpecialCells(xlCellTypeVisible)
问题:正在计算该标题的已过滤行。
Function CountByColor(CellColor As Range, CountRange As Range)
Application.Volatile
Dim ICol As Integer
Dim TCell As Range
ICol = CellColor.Interior.ColorIndex
For Each TCell In CountRange.SpecialCells(xlCellTypeVisible)
If ICol = TCell.Interior.ColorIndex Then
CountByColor = CountByColor + 1
End If
Next TCell
End Function
答案 0 :(得分:0)
我不是SpecialCells
的忠实粉丝,因为它们存在一些更新困难。因此,在测试隐藏行时,我会去旧学校,如下面的代码所示:
Function CountByColor(CellColor As Range, CountRange As Range)
Application.Volatile
Dim ICol As Integer
Dim TCell As Range
ICol = CellColor.Interior.ColorIndex
For Each TCell In CountRange.Cells
If Not TCell.EntireRow.Hidden And ICol = TCell.Interior.ColorIndex Then
CountByColor = CountByColor + 1
End If
Next
End Function