[英]Copy Paste Columns from one sheet to another sheet based on Autofilter
I am trying to copy data from sheet to another sheet based on a filter.我正在尝试根据过滤器将数据从工作表复制到另一个工作表。
Based on Column Q where autofilter criteria is "P", I need to copy column T & U from sheet ORD_CS to sheet Namechk.根据自动筛选条件为“P”的列 Q,我需要将列 T & U 从工作表 ORD_CS 复制到工作表 Namechk。
Here is my code.这是我的代码。 No error but the entire column is getting copied.没有错误,但整个列都被复制了。
Sub Macro26()
'
'Match Personal Names
'
'
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
Try this:试试这个:
sht.Range("T7:U99999").SpecialCells(xlCellTypeVisible).Copy sht1.Range("A1")
instead of而不是
sht.Range("T7:U99999").Copy
sht1.Range("A1").PasteSpecial
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.