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

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
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,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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