Hi
My code below works fine, but it copies all data to another worksheet. My data has 21 columns. When I execute the following code, it copies all 21 columns data without header to another worksheet. so if I just want to copy data in column 2 and column 21 without header to another worksheet, how do I modify the code?
My code below works fine, but it copies all data to another worksheet. My data has 21 columns. When I execute the following code, it copies all 21 columns data without header to another worksheet. so if I just want to copy data in column 2 and column 21 without header to another worksheet, how do I modify the code?
Code:
Sub filter_test()
Dim rang As Range
Set wt = ThisWorkbook.Sheets("Sheet1")
wt.UsedRange.AutoFilter field:=21, Criteria1:="<>0", Operator:=xlFilterValues
Set rang = wt.UsedRange.Offset(1, 0)
Set rang = rang.Resize(rang.Rows.Count - 1)
Set rang = rang.SpecialCells(xlCellTypeVisible)
rang.Copy ThisWorkbook.Sheets("Sheet2").Range("A1")
End Sub