find第一个可见的单元格,并获得参考

我试图select第一个可见的单元格后,使用自动筛选器。

If First.AutoFilter.Range.Columns(1).SpecialCells(xlVisible).Count - 1 > 0 Then Range("A1").Select Do ActiveCell.Offset(1, 0).Select Loop While ActiveCell.EntireRow.Hidden = True 

但是下一步我需要使用这个单元格,所以我需要它的行号和列号。 我怎么能得到它? (不使用lastrow和lastcolumn)

你可以试试(前三行用作示例代码)

更新了用户评论

 Dim rng1 As Range Dim rng2 As Range Set rng1 = [a1:a10] rng1.AutoFilter Field:=1, Criteria1:="4" If rng1.SpecialCells(xlVisible).Count > 1 Then Set rng2 = rng1.Offset(1, 0).Resize(rng1.Rows.Count - 1, 1).SpecialCells(xlCellTypeVisible).Cells(1, 1) MsgBox rng2.Address End If 

你可以使用ActiveCell.RowActiveCell.Column

这也将循环通过列A:

 Option Explicit Sub LoopThroughVisibleColA() Dim MySheet As Worksheet Dim FilterRange As Range, ColumnARange As Range, _ Cell As Range Dim LastRow As Long, LastCol As Long 'set worksheet for easy reference Set MySheet = ThisWorkbook.Worksheets("Sheet1") 'identify the ranges for our filter and loop action LastRow = MySheet.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row LastCol = MySheet.Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column Set FilterRange = Range(MySheet.Cells(1, 1), MySheet.Cells(LastRow, LastCol)) Set ColumnARange = Range(MySheet.Cells(1, 1), MySheet.Cells(LastRow, 1)) 'apply filter: in this example, filter column A for values >4 FilterRange.AutoFilter Field:=1, Criteria1:=">4" 'loop through the visible cells in our column A range For Each Cell In ColumnARange.SpecialCells(xlCellTypeVisible) If Cell.Row <> 1 Then 'skip the header row MsgBox ("We're in row " & Cell.Row & " and column " & Cell.Column) End If Next Cell End Sub 

你可以使用Application.Sendkeys "{DOWN}", True然后读取Selection.Address