Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 89371

Copy Filtered Data to another Workbook

$
0
0

I am trying to copy filtered data to another workbook and it is giving me Run-Time error '1004'.

Please help.

Sub DS()
'' DS Macro
'
    Dim wb As Workbook

    Set wb = Workbooks.Open("H:\L\Roy\H AND E\2020\SAP - ZPSD02_template2\")
''Selection.AutoFilter
    Worksheets("ST TO ST").Range("$A$1:$O$1").AutoFilter Field:=12, Criteria1:="PENDING"
    lastRow = Worksheets("ST TO ST").Range("J"& Worksheets("ST TO ST").Rows.Count).End(xlUp).Row
    'ActiveWindow.SmallScroll Down:=-12
    Worksheets("ST TO ST").Range("$A$1:$O$1").AutoFilter Field:=10, Criteria1:="U3R", Operator:=xlOr, Criteria2:="U2R"
    Worksheets("ST TO ST").Range("J2:J"& lastRow).SpecialCells(xlCellTypeVisible).Copy _
                                 Destination:=wb.Sheets("Sheet1").Range("A1")
    Worksheets("ST TO ST").Range("C2:C"& lastRow).SpecialCells(xlCellTypeVisible).Copy _
                                 Destination:=wb.Sheets("Sheet1").Range("B1")
    Worksheets("ST TO ST").Range("D2:D"& lastRow).SpecialCells(xlCellTypeVisible).Copy _
                                 Destination:=wb.Sheets("Sheet1").Range("E1")
    Worksheets("ST TO ST").Range("H2:H"& lastRow).SpecialCells(xlCellTypeVisible).Copy _
                                 Destination:=wb.Sheets("Sheet1").Range("F1")
End Sub

Viewing all articles
Browse latest Browse all 89371

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>