find下一个可见的行

我正在尝试编写一个函数来返回自动筛选列表中的下一个可见行。

在具有自动过滤范围的工作表中,下面的代码返回一个#VALUE错误:

Function FindNextVisible(S As Range) As Range Dim L As Range Dim R As Range Dim counter As Integer counter = 1 Set L = Range(S, S.End(xlDown)).Cells.SpecialCells(xlCellTypeVisible) For Each R In L counter = counter + 1 If counter = 2 Then FindNextVisible = R Next End Function 

我怀疑一个初学者错误…

更新1:好的build议。 我不能使用SpecialCells。 不幸的是,VBA在我身上并不强壮,而我在Sub版本上遇到了麻烦。

也许还有另一种方式。 我想比较非连续(由于过滤)行之间的文本,但我不知道如何提供该公式与下一个可见行的引用。

以下应该完成你正在寻找的东西。

 Public Function NextVisibleCell(Range As Range) As Range Application.Volatile Dim i As Long Set Range = Range.Cells(Range.Rows.Count, Range.Columns.Count) For i = 1 To Rows.Count - Range.Row If Not Range.Offset(i).EntireRow.Hidden Then Set NextVisibleCell = Range.Offset(i) Exit Function End If Next i End Function