VBA code help please

STIRRELL

Board Regular
Joined
Dec 30, 2010
Messages
62
Office Version
  1. 365
Hi, I am trying to autofilter on 2 criteria and my macro keeps throwing an error message.Auto filter method of range class failed.
I made sure the filter was not on when I ran the code.

Sub FILTER_COPY_PASTE()
Worksheets("Certify").Select
With ActiveSheet.Range("A1:AB1")
.AutoFilter Field:=6, Criteria1:="20"
.AutoFilter Field:=28, Criteria1:="X"
End With

ActiveSheet.Range("A2:X5000").SpecialCells(xlCellTypeVisible).Copy
Worksheets("20").Select.Range("A1").PasteSpecial Paste:=xlPasteAll
Worksheets("Certify").AutoFilterMode = False
End Sub

Please help what am I doing wrong?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Perhaps try this:
VBA Code:
Sub FILTER_COPY_PASTE()
Worksheets("Certify").Select
With ActiveSheet.Range("A1:AB1")
.AutoFilter Field:=6, Criteria1:="20"
.AutoFilter Field:=28, Criteria1:="X"
End With

ActiveSheet.Range("A2:X5000").SpecialCells(xlCellTypeVisible).Copy Destination:=Worksheets("20").Range("A1")
Worksheets("Certify").AutoFilterMode = False
End Sub

I'm personally getting an error in your code due to this line:
VBA Code:
Worksheets("20").Select.Range("A1").PasteSpecial Paste:=xlPasteAll
 
Upvote 0
Thank you, but my macro keeps stopping at the 2nd autofilter criteria. Do you have any other suggestions?
 

Attachments

  • Capture.JPG
    Capture.JPG
    17.8 KB · Views: 9
Upvote 0
That is not the same code you originally posted. Try using your original code.
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,318
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top