简体   繁体   English

基于自动过滤器将粘贴列从一张工作表复制到另一张工作表

[英]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.

相关问题 VBA从自动筛选器中复制并粘贴到另一张工作表中,输出一行 - VBA Copy and Paste in another Sheet from AutoFilter outputting one row 自动过滤器根据2个标准复制并粘贴到不同的工作表 - Autofilter to copy and paste to different sheet based on 2 criterias 根据条件将列复制并粘贴到另一张工作表 - Copy and paste columns to another sheet based on a criteria 从另一张纸上的单元格值复制同一张纸中范围的一部分的粘贴范围 - Copy Range From One Sheet Paste Part of Range In Same Sheet Based On Cell Value On Another Sheet 复制将行从一张纸粘贴到另一张纸 - Copy paste a row from one sheet to another 将一张图片从一张纸复制并粘贴到另一张纸上 - copy & paste a picture from one sheet to another 将范围从一张纸复制/粘贴到另一张纸 - Copy/Paste Range from one sheet to another 从工作表复制范围,然后粘贴到不同列的另一工作表中 - Copy range from a sheet and paste into another sheet in different columns 如何复制一张纸中的特定列并粘贴到另一张纸中的不同范围? - How to copy specific columns from one sheet and paste in another sheet in a different range? 复制列直到一张纸的最后一行,然后粘贴到另一张纸的下一个空行 - Copy columns until last row from one sheet and paste to the next empty row of another sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM