I have a routine that filters a spreadsheet containing 27 columns of data. After the filter I copy the visible rows to paste into another spreadsheet. I really don't need the whole row, just a few specific columns of data. How do I select just those ranges to copy/paste? My code is below, with the "Copy and paste only the filtered data" part being what I think needs changing. Any help would be appreciated.
'Restrain the filter to cells from A1 to the last entry in column X
With DstWkb.Worksheets("APRData")
Set rng = .Range("A1:X1")
Set RngEnd = .Cells(Rows.Count, rng.Column).End(xlUp)
Set rng = IIf(RngEnd.Row < rng.Row, rng, .Range(rng, RngEnd))
End With
'Filter the data using column M
rng.EntireRow.Autofilter Field:=13, Criteria1:=("0")
'Trap the error if there were no matches
On Error Resume Next
'See whether there's data or not
Set rng2 = Range("A2:X" & Rows.Count).SpecialCells(xlCellTypeFormulas)
If rng2 Is Nothing Then
DstWkb.Worksheets("Report").Range("A65536").End(xlUp).Offset(1, 0) = "Congratulations! You have no Zero FTEs!"
Else
'Copy and paste only the filtered data
Range("J1").Activate
'Set rng = IIf(RngEnd.Row < rng.Row, rng, .Range(rng, RngEnd))
rng.SpecialCells(xlCellTypeVisible).copy _
Destination:=DstWkb.Worksheets("Report").Range("A65536").End(xlUp).Offset(1, 0)
End If
Bookmarks