如果存在自动过滤结果,则复制/粘贴宏

时间:2014-06-23 09:11:19

标签: vba excel-vba excel

我有以下代码。我正在应用具有不同条件的过滤器,当过滤器有行时它可以工作,但是当它没有时,我得到错误“属性让过程没有定义,属性获取过程没有返回对象”在“My_Range.Parent”行。 AutoFilter.Range.Copy”。

如何跳过这个空的“粘贴”继续我的宏?谢谢!

My_Range.AutoFilter Field:=14, Criteria1:="=FEDERAL"
My_Range.AutoFilter Field:=7, Criteria1:="=No"


    'Copy/paste the visible data to the new worksheet

    My_Range.Parent.AutoFilter.Range.Copy
        With Sheets("Federal").Range("c5")
        .PasteSpecial xlPasteValues
        .PasteSpecial xlPasteFormats
        Application.CutCopyMode = False
        '.Select
    End With


End If

1 个答案:

答案 0 :(得分:0)

跳过错误的简单方法是写:

On Error GoTo myerrorhandler 'put this line on the beginning of you sub/function
     ... your code ...
myerrorhandler: 'after error your code continues to execute from this line
     .... more of your code...

或者你可以写

On Error Resume Next 'your code will resume to next line of code after the error