1
votes

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
2
I don't see how the whole column could be copied. Do you really mean all million rows?SJR

2 Answers

1
votes

Try this:

sht.Range("T7:U99999").SpecialCells(xlCellTypeVisible).Copy sht1.Range("A1")

instead of

sht.Range("T7:U99999").Copy
sht1.Range("A1").PasteSpecial
0
votes
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