我有一个带自动筛选的Excel表。
在筛选后的表格中,只有少量行被筛选出来。
我的目标是迭代所有可见行以收集数据并复制到另一个工作表中。
我想找到一种方法来收集第一个可见行号的变量。
我的草稿代码如下:
Dim cnp As String
Dim nome As String
Dim filter_rng As Range
Dim rw As Range
Dim last_row As Long 'last visible data row
Dim dest_row As Long 'row to paste the colected data
Set filter_rng = Range("A5:Y" & last_row).Rows.SpecialCells(xlCellTypeVisible)
'collect data
For Each rw In filter_rng.SpecialCells(xlCellTypeVisible)
workshett(1).Activate
cnp = Range("a" & rw).Value
nome = Range("b" & rw).Value
'copy data to another worksheet first data line is cell A2
Worksheet(2).Activate
Range("A" & dest_row + 1).Value = cnp
Range("b" & dest_row + 1).Value = nome
Next rw