![](/img/trans.png)
[英]Excel VBA copy-paste only the visible filtered values from one column to another
[英]How to copy and paste a filtered table using VBA from one column to another visible column?
为了将“C:C”列的过滤单元格(从第二行开始)复制到“D:D”列的相应行:
Sub copyVisCells()
Dim sh As Worksheet, lastR As Long, rngVS As Range, Ar As Range
Set sh = ActiveSheet
lastR = sh.Range("C" & sh.rows.count).End(xlUp).row
Set rngVS = sh.Range("C2:C" & lastR).SpecialCells(xlCellTypeVisible) 'here it needs error checking in case of no visible cells...
For Each Ar In rngVS.Areas
Ar.Copy Ar.Offset(0, 1)
Next Ar
End Sub
如果您可以根据从 B:B 复制值的内容定义规则,让我们说 D:D 中可见单元格之前的一行,则可以修改代码来执行此操作,但您必须根据要执行的规则进行说明它...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.