The AutoFilter Method of Range Class Failed – 5 Solutions

 

This is the sample dataset.

AutoFilter method of Range class failed

Soltion 1 – Correcting the Field Number

Filter the following range based on the sales values greater than 2500 with the help of a VBA code.

AutoFilter method of Range class failed

Use this code:

Sub fixing_autofilter_issue_1()

Dim sht As Worksheet
Set sht = Worksheets("Field Number")
sht.Range("B3:D3").AutoFilter field:=100, Criteria1:=">=2500"

End Sub

Here, field: is the column number in the range, which was assigned to 100.

Correcting field number

Press F5 and the error message AutoFilter method of Range Class Failed will be displayed.

AutoFilter method of Range class failed

Use the correct field number corresponding to the column number in the range (3, here the serial number of the Sales column).

Sub fixing_autofilter_issue_1()

Dim sht As Worksheet
Set sht = Worksheets("Field Number")
sht.Range("B3:D3").AutoFilter field:=3, Criteria1:=">=2500"

End Sub

Correcting field number

  • Press F5.
    Filter your range. No error message will be displayed.

AutoFilter method of Range class failed

Read More: Excel VBA to Check If AutoFilter is On


Solution 2 – Using a Correct Range

To apply the filter in the following dataset based on the Sales column for values greater than $2,500.00:

AutoFilter method of Range class failed

  • Used the following code.
Sub fixing_autofilter_issue_2()

Dim sht As Worksheet
Set sht = Worksheets("Range")
sht.Range("D3:D100").AutoFilter field:=3, Criteria1:=">=2500"

End Sub

the range D3:D100 and the field number 3 do not match as this range contains  one column only.

using a correct range

Press F5 and the error message will be displayed.

AutoFilter method of Range class failed

  • Change the code:
Sub fixing_autofilter_issue_2()

Dim sht As Worksheet
Set sht = Worksheets("Range")
sht.Range("B3:D3").AutoFilter field:=3, Criteria1:=">=2500"

End Sub

The range changed to B3:D3.

using a correct range

  • Press F5.
    Filter your range. No error message will be displayed.

AutoFilter method of Range class failed


Solution 3 – The AutoFilter Method of Range Class Failed Problem Due to a Filtering Table

The filter option is used with a code to filter this table based on the Sales column.

AutoFilter method of Range class failed

The following code is used.

Sub fixing_autofilter_issue_3()

Dim sht As Worksheet
Set sht = Worksheets("Table")
sht.Range("B3:D3").AutoFilter field:=3, Criteria1:=">=2500"

End Sub

This is the output.

filtering Table

Press F5 and the error message will be displayed.

filtering Table

  • Convert the table into a range.
  • Select the table and go to Table Design >> Tools >> Convert to Range.

AutoFilter method of Range class failed

  • A message box will be displayed.
  • Click Yes.

filtering Table

This is the output.

filtering Table

  • Use the previous code again.
Sub fixing_autofilter_issue_3()

Dim sht As Worksheet
Set sht = Worksheets("Table")
sht.Range("B3:D3").AutoFilter field:=3, Criteria1:=">=2500"

End Sub

filtering Table

  • Press F5.
    This is the output.

AutoFilter method of Range class failed

Read More: VBA Autofilter: Sort Smallest to Largest


Solution 4 – AutoFilter Method of Range Class Failed Problem Due to Filtering a Pivot Table

The following Pivot Table contains sales values in the second column.

AutoFilter method of Range class failed

Use the following code.

Sub fixing_autofilter_issue_4()

Dim sht As Worksheet
Set sht = Worksheets("Pivot")
sht.Range("A3:B3").AutoFilter field:=2, Criteria1:=">=2500"

End Sub

2 is the second column in A3:B3.

filtering Pivot Table

After pressing F5, you will get the error message AutoFilter method of Range Class Failed.

filtering Pivot Table

  • Apply the AutoFilter method to the source range of the Pivot table.

filtering Pivot Table

  • Enter the following code for this source range.
Sub fixing_autofilter_issue_4_1()

Dim sht As Worksheet
Set sht = Worksheets("Source")
sht.Range("B3:D3").AutoFilter field:=3, Criteria1:=">=2500"

End Sub

filtering Pivot Table

  • Press F5.
    You will be able to filter the range based on the given criteria.

AutoFilter method of Range class failed


Solution 5 –  Using the Whole Range Instead of the Header

Apply the AutoFilter method to the following range.

AutoFilter method of Range class failed

Use the following code to apply the filter.

Sub fixing_autofilter_issue_5()

Dim sht As Worksheet
Set sht = Worksheets("Header")
sht.Range("B3:D11").AutoFilter field:=3, Criteria1:=">=2500"

End Sub

B3:D11 is the whole dataset and can cause an error message.

selecting header as range

  • Change the code and use the header as a range.
Sub fixing_autofilter_issue_5()

Dim sht As Worksheet
Set sht = Worksheets("Header")
sht.Range("B3:D3").AutoFilter field:=3, Criteria1:=">=2500"

End Sub

selecting header as range

After pressing F5, you will see the result.

AutoFilter method of Range class failed

Read More: Excel VBA: Remove AutoFilter If It Exists


Download Workbook


Related Articles

Get FREE Advanced Excel Exercises with Solutions!
Tanjima Hossain
Tanjima Hossain

TANJIMA HOSSAIN is a marine engineer who enjoys working with Excel and VBA programming. For her, programming is a handy, time-saving tool for managing data, files, and online tasks. She's skilled in Rhino3D, Maxsurf C++, MS Office, AutoCAD, and Excel & VBA, going beyond the basics. She holds a B.Sc. in Naval Architecture & Marine Engineering from BUET and is now a content developer. In this role, she creates tech-focused content centred around Excel and VBA. Apart from... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo