在filterVBA后返回行号

有什么方法可以select或返回过滤后的第一个可见细胞的单元格地址? 我到目前为止,并坚持在筛选后select第一个可见的单元格。

fileSheet.Name = "Test" With fileSheet .Range("A2").Activate ActiveWindow.FreezePanes = True .Range("A2").AutoFilter field:=4, Criteria1:=">1" 'select the first visible cell after column header End With 

我实际上有列标题。

 dim firstCell as Range set firstCell = fileSheet.usedRange.offset(1,0).SpecialCells(xlCellTypeVisible)(1) 

UsedRange返回正在使用的工作表的范围(好的,有时太多,但在这种情况下无关紧要), offset(1, 0)向下移动一行,使标题被忽略, SpecialCells(xlCellTypeVisible)得到一个列表所有可见的单元格,因此最后(1)返回第一个可见单元格。

给定的范围为A1 ,这将给你第一个可见的单元格:

 Range("A1").Offset(1, 0).SpecialCells(xlCellTypeVisible)(1).Row 
  1. 偏移将跳过标题行
  2. SpecialCells将控制移动到可见的单元格。
  3. 从可见的单元格中select第一个项目。
  4. 查找行

尝试这个

 lastrow=cells(rows.count,"A").end(xlup).row For x=1 To lastrow If cells(x,"A")=criteria1 Then rowfound=x endif Next x 

在开始时将variables变暗