Reputation: 1
ActiveSheet.Range("a1:b1").AutoFilter
the above code works fine but sometimes gives error 'autofilter method of range class failed'. my intention is to enable filtering for some columns without any criteria. is there any better way?
Upvotes: 0
Views: 17366
Reputation: 612
I was just dealing with a similar situation, where Range would not execute AutoFilter() no matter what I did. I was able to solve it by removing Range from the equation entirely, using Selection as follows:
ActiveSheet.Range("a1:b1").Select()
Application.Selection.AutoFilter()
Whatever the problem was, selection bypassed it entirely.
Upvotes: 0
Reputation: 3197
As a rule I always turn off all prior filters, just in case.
ActiveSheet.AutoFilterMode = False 'turn off prior filters
ActiveSheet.Range("A1:B1").AutoFilter 'turn on new clean filter
Upvotes: 6