简体   繁体   English

Excel SpecialCells

[英]Excel SpecialCells

101 class for me. 我上101课。 Attempting to count colors in a Pivot table. 尝试计算数据透视表中的颜色。 Down below is counting all colors including the ones filtered out. 下面的数字是所有颜色的计数,包括过滤出的颜色。

Is there a way to only count the rows being displayed? 有没有一种方法只计算正在显示的行?

This method is not working: 此方法不起作用:

For Each TCell In CountRange.SpecialCells(xlCellTypeVisible)

Problem: The filtered out rows for that heading are being counted. 问题:正在计算该标题的过滤出的行。

    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

I'm not a big fan of SpecialCells as there are some updating difficulties with them. 我不是SpecialCells忠实SpecialCells因为它们存在一些更新方面的困难。 As a result, I go old school when it comes to testing for hidden rows, as in the code below: 结果,在测试隐藏行时,我去了老派 ,如下面的代码所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM