Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 49956

[SOLVED] copy specific column to another sheet after filtered data without header

$
0
0
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?

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


Viewing all articles
Browse latest Browse all 49956

Trending Articles