您指定的宏将为您的活动工作表打开自动筛选。这将提供允许用户过滤到感兴趣的内容的列标题。假设这种工作表的过滤是你想要的,你可以使用类似的东西:
Dim r As Range
'Note: set r to something useful, such as worksheet.Cells
Dim vis As Range
Set vis = r.SpecialCells(xlCellTypeVisible)
'now vis holds a special "Range" object referring to the visible cells.
'since (auto) filtering hides some cells, this vis range will help show only the cells that remain visible.
'the output of SpecialCells, you should assume holds a complex Range,
'which is composed of multiple Areas that are wrapped in one single Range object
'the separate areas help you distinguish the visible cells from the hidden cells
'fyi, various safety checks you can do: vis Is Range, vis Is Nothing
Dim a as Areas
Set a = r.Areas
Dim cr as Range
For Each cr in a
'cr refers to a single (i.e. normal and contiguous) area range
'where you can use cr.Row, cr.Column, cr.Rows.Count, cr.Columns.Count
Next
因此,当您进行过滤时,您可以使用 SpecialCells(xlCellTypeVisible) 来显示非隐藏单元格,这些单元格表示为具有包含表示连续范围的区域的范围。