简体   繁体   English

vba过滤行的行号

[英]vba Row numbers for filtered rows

I have this code to capture the row number in a filtered table, do some things and then go to the next visible row. 我有这段代码来捕获已过滤表中的行号,执行一些操作,然后转到下一个可见行。 I works great for the first row. 我在第一行表现出色。

Sub test()

Dim rn As Long
Dim cell As Range
Dim rng As Range


    Set rng = Sheets("FabricatedParts").Range("A:A").SpecialCells(xlCellTypeVisible)
        rn = Sheets("FabricatedParts").UsedRange.Offset(1, 0).SpecialCells(xlCellTypeVisible).Row
         For Each cell In rng
            With ActiveSheet
                .Range("B14").Value = [Parts].Cells(rn, [Parts[Part.]].Column)
            End With
            'rn = Next Visible Row #???.row
         Next cell

End Sub

When I change to offset(1, 0) to offset(2, 0) it still returns the row number for the first visible row(in this case 10). 当我将offset(1,0)更改为offset(2,0)时,它仍返回第一个可见行的行号(在本例中为10)。 I am looking for a VBA statement that will return the row number for the next visible row and pass that number to the rn variable. 我正在寻找一个VBA语句,该语句将返回下一个可见行的行号,并将该行号传递给rn变量。 For the filtered range I am testing the next row number is 11, the next 165, the next 166 etc. Thank you for your time. 对于过滤范围,我正在测试下一个行号是11,下一个165,下一个166等。谢谢您的时间。

Use the row number of the cell loop. 使用单元格循环的行号。

Sub test()

Dim rn As Long
Dim cell As Range
Dim rng As Range


    Set rng = Sheets("FabricatedParts").Range("A:A").SpecialCells(xlCellTypeVisible)
         For Each cell In rng
            rn = cell.row
            With ActiveSheet
                .Range("B14").Value = [Parts].Cells(rn, [Parts[Part.]].Column)
            End With
         Next cell

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM