Tricky AutoFilter VBA Question for the VBA Gurus

Martin514

New Member
Joined
Nov 12, 2008
Messages
7
Hopefully some Excel VBA guru can help me on this :) I need a solution for the case below that I plan on using for an application I'm developing:

Case: A sheet can have an Autofiltered Range and many Autofiltered Tables(ListObjects).

Requirement: I need VBA code which can identify these objects on a sheet and put them in a VBA Collection which I can iterate through at a later point. The Collection can be populated with a generic VBA Object Type which will support both Range and ListObjects

Problem: Its easy to identify Tables(ListObjects) on a sheet - simply iterate through the Worksheet.Tables collection and determine if the Autofilter is applied. What is difficult is to identify the location of an Autofiltered Range object on a sheet with Autofiltered Tables(ListObjects)

Any thoughts on how to solve this problem?

Martin
 
Last edited:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
How about this ?

Code:
Function AutoFilterPLUSListObjectTablesCollection(ByVal Sh As Worksheet) As Collection
    Dim i As Long, oCol As New Collection
    
    For i = 1 To Sh.ListObjects.Count
        If Sh.ListObjects(i).ShowAutoFilter Then
            oCol.Add Sh.ListObjects(i).Range
        End If
    Next i
    If Sh.AutoFilterMode Then oCol.Add Sh.AutoFilter.Range
    Set AutoFilterPLUSListObjectTablesCollection = oCol
End Function

Sub Test()
    Dim element As Object
    For Each element In AutoFilterPLUSListObjectTablesCollection(Sheet1)
        MsgBox element.Address
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,871
Members
449,054
Latest member
juliecooper255

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