简体   繁体   中英

Run-Time error '1004 - AutoFilter method of Range class failed

I am getting the above error when running the below code. I am very new to VBA and need some assistance in debugging.

Sub TransferTest1()

Dim INQUIRE As Worksheet
Dim QUOTE As Worksheet
Dim ORDER As Worksheet
Dim YString As String
Dim RecString As String

Set INQUIRE = ActiveWorkbook.Sheets("Inquiries")
Set QUOTE = ActiveWorkbook.Sheets("Quotes")
Set ORDER = ActiveWorkbook.Sheets("Orders")

With INQUIRE.Range("A6:K1200")
    .AutoFilter 11, "Y"
    .Offset(1).Resize(, 7).Copy QUOTE.Range("A6")  ' columns A:G
    .AutoFilter
End With

With QUOTE.Range("A6:N1200")
    .AutoFilter 14, "Rec'vd"
    .Offset(1).Resize(, 7).Copy ORDER.Range("A6") ' columns A:G
    .Offset(1).Resize(, 2).Offset(11).Copy ORDER.Range("K6")  ' columns L:M
    .AutoFilter
End With

End Sub

Thank you for the help in advance!

R. Smithey

Precede each call to .AutoFilter with,

if .parent.autofiltermode then .parent.autofiltermode = false

This will turn off any pre-existing .AutoFilters if they exist and do nothing if they do not exist.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM