AutoFilter

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
786
Office Version
  1. 365
Hi,

have this code for filtering but I am getting this error:

invalid use of Me keyword,

Code:
Private Sub ReapplyFilter()    
    Application.EnableEvents = False
    
    With Me.[a1]
        .AutoFilter
        .AutoFilter Field:=4, Criteria1:="r", Operator:=xlAnd
    End With
    
    Application.EnableEvents = True
    
End Sub

also how can get the another code to put the list back original list before filtering.

thanks,
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hello,

Instead of Me .... have you tried ActiveSheet ...?

ActiveSheet.Cells(1,1).AutoFilter
 
Last edited:
Upvote 0
thank you.

but no that good in vba when I added your suggestion gave me another error would you mind re writing the whole code inserting your suggestion.

thanks again
 
Upvote 0
Try this

Code:
Private Sub ReapplyFilter()
    Application.EnableEvents = False
    ActiveSheet.Range("A1").AutoFilter
    ActiveSheet.Range("A1").AutoFilter Field:=4, Criteria1:="r"
    Application.EnableEvents = True
End Sub
 
Upvote 0
In fact, these lines are not necessary, since an autofilter does not activate any event.

Application.EnableEvents = False
Application.EnableEvents = True

Then:

Code:
Private Sub ReapplyFilter()
    ActiveSheet.Range("A1").AutoFilter
    ActiveSheet.Range("A1").AutoFilter Field:=4, Criteria1:="r"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,213
Members
452,618
Latest member
Tam84

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