vba 过滤器VBA后返回行号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45759474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 13:07:36  来源:igfitidea点击:

Returning Row number after filter VBA

excelvbaexcel-vba

提问by

Is there any way I can select or return the cell address of the first visible cell after filtering? I have this so far, and stuck in selecting the first visible cell after filter.

有什么办法可以选择或返回过滤后第一个可见单元格的单元格地址?到目前为止,我有这个,并坚持选择过滤器后的第一个可见单元格。

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

I actually have column headers.

我实际上有列标题。

采纳答案by FunThomas

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

UsedRangereturns the range of the sheet in use (okay, sometimes too much but that doesn't matter in this case), offset(1, 0)moves one line down so that the headerlines are ignored, SpecialCells(xlCellTypeVisible)gets a list of all cells that are visible and therefore the last (1)returns the first visible cell.

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

回答by M_Idrees

With given range as A1, this would give you the first visible cell:

给定范围为A1,这将为您提供第一个可见单元格:

Range("A1").Offset(1, 0).SpecialCells(xlCellTypeVisible)(1).Row
  1. Offset will skip the header row
  2. SpecialCells will move control to visible cells.
  3. Pick first item from the visible cells.
  4. Find Row
  1. Offset 将跳过标题行
  2. SpecialCells 将控制移动到可见单元格。
  3. 从可见单元格中选择第一项。
  4. 查找行

回答by Mitch

Try this

尝试这个

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

Dim the variables at the start

在开始时变暗变量

回答by Muhammad Hazlan

Here's a code if you want to pick the first row after filter, I have try it

如果您想在过滤器后选择第一行,这是一个代码,我已经尝试过了

Code:

代码:

activesheet.AutoFilter.Range.offset(1).SpecialCells(xlCellTypeVisible).Cells(1, 2).select