VBA AutoFilter运行时错误1004:Range类的AutoFilter方法失败

时间:2018-01-11 09:11:37

标签: excel vba excel-vba autofilter

我的代码如下,它会在End Sub之前的最后一行语句中抛出此错误。有人可以建议问题是什么吗?

    Sub Copy()

    Set target_book = ActiveWorkbook.Sheets("Sheet2")
    ActiveWorkbook.Sheets("Sheet1").Activate
    last_row_2 = ActiveSheet.Range("B100000").End(xlUp).Row

    For k = 2 To last_row_2
        ActiveWorkbook.Sheets("Sheet1").Activate
        Range("A" & k & ":Y" & k).Select
        Selection.Copy
        target_book.Select
        last_row = target_book.Range("B100000").End(xlUp).Row
        target_book.Range("B" & last_row + 1 & ":Z" & last_row + 1).Select
        Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        Application.CutCopyMode = False
    Next k

    target_book.Activate
    ActiveSheet.Range("A13:Z13").AutoFilter Field:=5, Criteria1:="<>", 
    VisibleDropDown:=True

    End Sub

0 个答案:

没有答案