移到下一行已过滤数据vba excel

时间:2019-10-03 09:29:19

标签: excel vba

我有这样的床单:

Picture given

我要做的就是,我可以向下移动下一行并显示其值。 我已经有了代码:

Sub test()

'Select the first row.

MsgBox Sheet1.AutoFilter.Range.Offset(1).SpecialCells(xlCellTypeVisible).Cells(1, 3).Value

'Then move down to the second row of filtered data.

'Code

End Sub

有人可以建议如何完成我的上述课程吗?

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您可以尝试实施/调整以下内容:

enter image description here

Sub VisRows()

Dim rng As Range, lr As Long
With Sheet1 'Change accordingly
    lr = .Cells(.Rows.Count, "B").End(xlUp).Row
    Set rng = .Range("B2:B" & lr)
    'Apply your filter
    For Each cl In rng.SpecialCells(xlCellTypeVisible)
        Debug.Print cl.Value
    Next cl   
End With

End Sub

enter image description here