Excel SpecialCells
101class为我。 试图在数据透视表中统计颜色。 在下面计算所有的颜色,包括被过滤的颜色。
有没有办法只计算显示的行?
此方法不起作用:
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
我不是SpecialCells
忠实粉丝,因为他们有一些更新的困难。 因此,当我们开始testing隐藏行时,我就开始上学了 ,如下面的代码所示:
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