Autofilter Method of range class failed

Tolus

New Member
Joined
Nov 21, 2019
Messages
7
I try to run the following code, where I find the proper column in a sheet to format it.
Then I use Autofilter to set a filter criteria on the same sheet (but different value).

the following error appears: Autofilter Method of range class failed

If I use the very same code, but format the two colomns in the beginning using fixed range
Code:
    'Range("C:C").NumberFormat = "General"
    'Range("E:E").NumberFormat = "General"

it works fine.
Please help :)
Code:
    Dim Row as Variant
    Dim FilterRow as Variant

    Row = Rows("1:1").Find(What:="Erstellt", LookAt:=xlWhole).Column
    Range(Cells(1, Row), Cells(100000, Row)).NumberFormat = "General"

    Row = Rows("1:1").Find(What:="bestätigt", LookAt:=xlWhole).Column
    Range(Cells(1, Row), Cells(100000, Row)).NumberFormat = "General"
   

    If WrkShtRSTand.AutoFilterMode Then
    WrkShtRSTand.ShowAllData
    Else
    WrkShtRSTand.Range("A1").AutoFilter
    End If
     
    FilterRow = Rows("1:1").Find(What:="Einkäufergruppe", LookAt:=xlWhole).Column
    WrkShtRSTand.UsedRange.AutoFilter Field:=FilterRow, Criteria1:=Array("AZ04", "AZ05", "AZ07", "AZ08"), Operator:=xlFilterValues
 
That explains it. It is a conflict between the usedrange and the fact your data is in a Table. You should use:

Code:
    WrkShtRSTand.ListObjects(1).Range.AutoFilter Field:=FilterRow, Criteria1:=Array("AZ04", "AZ05", "AZ07", "AZ08"), Operator:=xlFilterValues

to just filter the Table.
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,222,496
Messages
6,166,381
Members
452,032
Latest member
TegIT

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