尝试从工作表复制数据并根据过滤器将其粘贴到另一张工作表。
基于列Q,其中自动过滤器标准是" P",我需要复制列T& U从表ORD_CS到表Namechk。这是我的代码。没有错误,但整个列都被复制了。
Sub Macro26() ' '匹配个人姓名 '
'
Dim i As Long, LR As Long
Dim sht, sht1 As Worksheet
Set sht = ActiveWorkbook.Worksheets("ORD_CS")
Set sht1 = ActiveWorkbook.Worksheets("Namechk")
sht.Range("A7:AC7").AutoFilter Field:=17, Criteria1:="P"
sht.Range("T7:U99999").Copy
sht1.Range("A1").PasteSpecial
Application.CutCopyMode = False
End Sub
VBA全新。有人可以帮忙吗?谢谢
答案 0 :(得分:1)
试试这个:
sht.Range("T7:U99999").SpecialCells(xlCellTypeVisible).Copy sht1.Range("A1")
而不是
sht.Range("T7:U99999").Copy
sht1.Range("A1").PasteSpecial
答案 1 :(得分:0)
Sub filter_paste()
Dim sht, sht1 As Worksheet
Set sht = ActiveWorkbook.Worksheets("ORD_CS")
Set sht1 = ActiveWorkbook.Worksheets("Namechk")
sht.Range("A:AC").AutoFilter Field:=17, Criteria1:="P"
sht.Range("T7:U99999").Copy sht1.Range("A1")
End Sub