简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM