crepe
asked on
Excel VBA Copying Data with Autofilter Crashes when there is no data to Copy
If there is data, the macro works perfectly but when there's no data in the AutoFilter, it crashes. What did I do wrong and how can I fix it? Thank you!!
' Copies Temperature errors to "Errors List"
With Sheets("All Data").Range("A3:T380")
.AutoFilter
.AutoFilter Field:=16, Criteria1:="1"
.Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row).SpecialCells(xlCellTypeVisible).Copy _
Sheets("Errors List").Range("F11")
.AutoFilter
End With
ActiveSheet.ShowAllData
' Copies Humidity Errors to "Errors List"
With Sheets("All Data").Range("A3:T380")
.AutoFilter
.AutoFilter Field:=14, Criteria1:="1"
.Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row).SpecialCells(xlCellTypeVisible).Copy _
Sheets("Errors List").Range("D11")
.AutoFilter
End With
ActiveSheet.ShowAllData
' Copies Operator Errors to "Errors List"
With Sheets("All Data").Range("A3:T380")
.AutoFilter
.AutoFilter Field:=11, Criteria1:="Yes"
.Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row).SpecialCells(xlCellTypeVisible).Copy _
Sheets("Errors List").Range("B11")
.AutoFilter
End With
' Remove any filters
ActiveSheet.AutoFilterMode = False
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thomas, I'll have to remember that trick. I typically just use On Error Resume Next :)
ASKER
Perfect! Thanks!