VBA AutoFilter

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

VBA AutoFilter

Post by jstevens »

Does the auto filter mode behave differently in a table?

The code below works just fine selecting Sheet1 then Sheet2 back to Sheet1. The auto filter will always be on within Sheet1. If I change the cells to a table and then select Sheet2 and back to Sheet1 the auto filter is off. Selecting Sheet2 and then Sheet1 will turn it on.

I'm not sure if this behavior is normal for a table or a bug.

Code: Select all

Private Sub Worksheet_Activate()   'This is Sheet1
    If Not ActiveSheet.AutoFilterMode Then
       ActiveSheet.Range("A1").AutoFilter
    End If
End Sub
Your comments are appreciated.
Regards,
John

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA AutoFilter

Post by HansV »

AutoFilterMode does not apply to tables. One worksheet can contain multiple tables, each of which can have autofilter arrows or not, independently of each other.

See autofilter mode not working when data formatted as table for alternative code.
Best wishes,
Hans

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: VBA AutoFilter

Post by jstevens »

Thanks Hans!
Regards,
John