Excel 2010 using vba AutoFilter to filter table by cell value returns '1004 Autofilter method of Range class failed'

eldarnegrin

New Member
Joined
Jul 9, 2013
Messages
4
Hi,
I've seen here some code samples which worked for different people, yet i cant manage to make it work.
facts:
I've checked the trust vba module in the trust center.

cell A1 contains the filter value 1 (i want to show only rows that contain 1 in column a)

table data on range("A2:D6")/table:ListObject("Table1") (I've tried both)
a b c d
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16

the code:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not ActiveSheet.AutoFilterMode Then ActiveSheet.Range("A2:A6").AutoFilter [COLOR=#ff0000]'tried with ActiveSheet.AutoFilterMode=False too instead of this line[/COLOR]
    Range("A2:A6").AutoFilter Field:=1, Criteria1:=Cells(1,1) [COLOR=#ff0000]'Tried with range here too instead of Cells reference, and also simple "1" as a static criteria[/COLOR]
End Sub

Nothing seems to work.. Thanks!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Welcome to MrExcel.

This is what the macro recorder gave me:

Code:
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:="1"
 
Upvote 0
Thanks very much :)
and yes i know i also recorded it and it works when i run it,
how can i make it work automatically?

Code:
Sub Macro1()
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:="=" & Cells(1, 1)
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,453
Members
448,898
Latest member
drewmorgan128

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