如何在应用filter后select第一个可见行

我在Excel中筛选表格,但我只想要显示的第一行。

使用Range.SpecialCells方法 ,在过滤的范围上使用xlCellTypeVisible参数。 .Rows(1).Cells应该是你想要的。

 Sub first_row() Dim rFirstFilteredRow As Range With Worksheets("Sheet1") With .Cells(1, 1).CurrentRegion 'do all the .autofilter stuff here With .Resize(.Rows.Count - 1, .Columns.Count).Offset(1, 0) If CBool(Application.Subtotal(103, .Cells)) Then Set rFirstFilteredRow = _ .SpecialCells(xlCellTypeVisible).Rows(1).Cells '~~> rFirstFilteredRow is not a copy of the first visible row 'do something with rFirstFilteredRow End If End With End With End With End Sub 

你将不得不抄录这个来适应你自己的AutoFilter方法的实现。


本机工作表SUBTOTALfunction被使用,因为它只计数可见的单元格。 这是一个简单的非破坏性的方式来确定是否有任何细胞参考filter已被应用。

 Worksheets("Raw").AutoFilter.Range.Offset(1).SpecialCells(xlCellTypeVisible).Cells(Row, Column)