【发布时间】:2020-07-03 14:56:48
【问题描述】:
我对 Excel VBA 中的宏有疑问。 我想在 Excel 中获取彩色单元格的数量,所以我编写了以下代码:
Application.ScreenUpdating = False
x = Range("D2:Y46").Select
For Each d In Selection
d.Select
If Selection.Interior.Color = 15773696 Then
Count = Count + 1
End If
Next
Application.ScreenUpdating = True
Range("C53").Select
Selection = Count
它工作正常,但是由于标题过滤器而隐藏了一些行。
当我使用上面的代码时,它也会显示隐藏单元格的输出,但我不希望结果包含隐藏单元格。在标题中过滤后,我只需要可查看单元格的结果。
有什么办法吗?
【问题讨论】:
-
查看此链接support.microsoft.com/kb/150363。或者,您也可以使用
Range("D2:Y46").SpecialCells(xlCellTypeVisible);)