应用过滤器后如何选择第一条可见行 [英] How to select the first visible row after applying a filter
本文介绍了应用过滤器后如何选择第一条可见行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在Excel中过滤表,但我只希望显示第一行.
I'm filtering a table in Excel but I only want the first line that appears.
推荐答案
使用 Range.SpecialCells方法和 xlCellTypeVisible 参数在过滤范围内. .Rows(1).Cells
应该是您想要的.
Use Range.SpecialCells method with the xlCellTypeVisible parameter on the filtered range. .Rows(1).Cells
should be what you want.
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
You will have to transcribe this to suit your own implementation of the AutoFilter Method.
本机工作表使用了SUBTOTAL函数,因为它仅计算可见的单元格.这是一种简单的非破坏性方法,可确定在应用过滤器后是否有任何要引用的单元格.
The native worksheet SUBTOTAL function was used as it only counts visible cells. This is an easy non-destructive way of determining whether there are any cells to reference after the filter has been applied.
这篇关于应用过滤器后如何选择第一条可见行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文