Reputation: 61
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
Upvotes: 1
Views: 143
Reputation: 1
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
Upvotes: 0
Reputation: 5450
Try this:
sht.Range("T7:U99999").SpecialCells(xlCellTypeVisible).Copy sht1.Range("A1")
instead of
sht.Range("T7:U99999").Copy
sht1.Range("A1").PasteSpecial
Upvotes: 1