2
我有一個帶有自動過濾器的Excel表。Excel VBA通過可視過濾行循環
在已過濾的表格中,我只有幾行過濾。
我的目標是強化所有可見的行以將數據複製到其他表單中。
我想要一種方式來收集一個變量與fisrt可見行號。
我的代碼草案:
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
GD Joao,如果我的答案解決了您的問題,那麼請接受它作爲正確的答案?您可以通過點擊我答案頂部的大「V」勾來完成。 – mtholen
謝謝。有用! –