+ Reply to Thread
Results 1 to 6 of 6

Displaying all Applied Filters

Hybrid View

  1. #1
    Registered User
    Join Date
    07-30-2014
    Location
    LI, NY
    MS-Off Ver
    2010
    Posts
    5

    Displaying all Applied Filters

    Hello Everyone, I have a user with a very large spreadsheet which contains company financials so I can't post it. But within this spreadsheet there are columns that span many pages and many many rows. The data is filtered on several columns. Is there a way to view all of the applied filters without having to go into each one or hover over each one and also important is that I also need to know the order the filters are applied? I found some code for a user defined function online to do this but I am hitting a block because if the filter has more then 2 selections checked the function fails and it won't tell me the order that they are applied in.

    Here is the code from online:
    Function FilterCriteria(Rng As Range) As String
        'will add function to let you see filters that are set on a worksheet
        'add this filter to a worksheet
        'put cursor where you want to see autofilter that is set
        'insert finction then user defined and choose filtercriteria
        'choose cell with filter for range
        'add &LEFT(SUBTOTAL(9,A5:A200),0)to the end of the formula
        
        Dim Filter As String
        Filter = ""
        On Error GoTo Finish
        With Rng.Parent.AutoFilter
            If Intersect(Rng, .Range) Is Nothing Then GoTo Finish
            With .Filters(Rng.Column - .Range.Column + 1)
                If Not .On Then GoTo Finish
                Filter = .Criteria1
                Select Case .Operator
                    Case xlAnd
                        Filter = Filter & " AND " & .Criteria2
                    Case xlOr
                        Filter = Filter & " OR " & .Criteria2
                End Select
            End With
        End With
    Finish:
        FilterCriteria = Filter
    End Function
    Thank you very much for any help, Kim
    Last edited by welch1198; 08-01-2014 at 11:48 AM.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Displaying all Applied Filters

    Hi Kim,

    Great question. See the attached file and complete code that follows which is based on similar code to yours. I would give credit to the author, but I lost the original link.

    Please note that there can be several ranges that can use AutoFilter on one sheet, but only one AutoFilter range can be active on one sheet at a time (at least in Excel 2003). If using more than one range per sheet, they SHOULD NOT BE side by side, because when AutoFilter hides rows, it may look like a non-AutoFilter range is being filtered.

    AutoFilter can be ON at the same time on several different sheets in the same workbook

    I called the function 'GetAutoFilterCriteria()' and created a SHORTCUT function 'AFC() ' that does the same thing to allow for less typing when implementing the function in a cell. Even though the function is declared Volatile (which means a recalculation occurs any time any cell on the sheet needs calculation), recalculation may not occur when switching between AutoFilter OFF and AutoFilter ON when there are no Autofilter criteria.

    Lewis

    Option Explicit
    
    Function AFC(Header As Range) As String
      'This is a SHORTCUT (to eliminate typing) for function GetAutoFilterCriteria()
      AFC = GetAutoFilterCriteria(Header)
    End Function
    
    
    Function GetAutoFilterCriteria(Header As Range) As String
      'This returns AutoFilter Criteria for ONE AutoFilter Column as text
    
      Dim bAutoFilterOn
    
      Dim sCriterion1 As String
      Dim sCriterion2 As String
    
      'Recalculate any time a calculation occurs in the Worksheet
      Application.Volatile
      
      'Get the current 'AutoFilter' State
      bAutoFilterOn = ActiveSheet.AutoFilterMode
    
      If bAutoFilterOn = False Then
        'Do Not Process - AutoFilter is OFF
        GetAutoFilterCriteria = "AutoFilterOff"
        
      ElseIf Header.Count > 1 Then
        'Do Not Process - Input Range must be ONE CELL
        GetAutoFilterCriteria = "#VALUE"
      Else
    
        'Process - AutoFilter is ON
        With Header.Parent.AutoFilter
    
          With .Filters(Header.Column - .Range.Column + 1)
    
            If Not .On Then
              GetAutoFilterCriteria = "No Filter"
            Else
                    
              sCriterion1 = .Criteria1
    
              If .Operator = xlAnd Then
                sCriterion2 = " AND " & .Criteria2
              ElseIf .Operator = xlOr Then
                sCriterion2 = " OR " & .Criteria2
              End If
          
              GetAutoFilterCriteria = UCase(Header) & ": " & sCriterion1 & sCriterion2
            
            End If
          
          End With
    
        End With
        
      End If
      
    End Function
    
    Sub FilterDateUsingTwoCriteria()
    
      Dim myStartDate As Date
      Dim myEndDate As Date
      
      myStartDate = Range("E7")
      myEndDate = Range("E8")
    
      Sheets("Sheet1").Select
      With ActiveSheet
                
       .AutoFilterMode = False
    
       .Range("C11:E11").AutoFilter
       
       .Range("C11:E11").AutoFilter Field:=3, _
           Criteria1:=">" & CDbl(myStartDate), _
           Operator:=xlAnd, _
           Criteria2:="<=" & CDbl(myEndDate)
    
     End With
     
    End Sub
    
    Sub AutoFilterClearAndOn()
      'This Clear then Turns ON AutoFilter
    
      With ActiveSheet
                
       .AutoFilterMode = False
    
       .Range("C11:E11").AutoFilter
       
     End With
      
     'Force recalculation of the cells that monitor AutoFilter status
     Range("C28:E28").Calculate
    
    End Sub
    
    Sub AutoFilterOff()
      'This Turns OFF AutoFilter on the Active Sheet
    
      ActiveSheet.AutoFilterMode = False
     
     'Force recalculation of the cells that monitor AutoFilter status
      Range("C28:E28").Calculate
    
    End Sub
    
    
    Sub TestGetAutoFilterCriteriaOnlyVBADirect()
      'This obtains AutoFilter Criteria using VBA only
      '
      'The Addresses of the AutoFilter 'Header Cells' are 'hard coded'
    
      Dim s As String
      Dim sData As String
      
      sData = "AutoFilter Criteria:" & vbCrLf
      s = "C11: " & GetAutoFilterCriteria(Range("C11"))
      sData = sData & s & vbCrLf
      s = "D11: " & GetAutoFilterCriteria(Range("D11"))
      sData = sData & s & vbCrLf
      s = "E11: " & GetAutoFilterCriteria(Range("E11"))
      sData = sData & s & vbCrLf
    
      MsgBox sData
    End Sub
    
    Sub TestGetAutoFilterCriteriaOnlyVBA()
      'This obtains AutoFilter Criteria using VBA only
      
      Dim ws As Worksheet
      Dim r As Range
    
      Dim s As String
      Dim sAddress As String
      Dim sCriteria As String
      Dim sData As String
      Dim sHeaderRange As String
      
      'Assign the Worksheet Object
      Set ws = ActiveSheet
      
      sHeaderRange = GetAutoFilterHeaderRangeAddress(ws)
      sData = "AutoFilter Criteria:" & vbCrLf
      
      If Len(sHeaderRange) = 0 Then
        sData = "AutoFilter Criteria:" & vbCrLf & "AutoFilterOff"
      Else
        For Each r In Range(sHeaderRange)
        
          'Get the next 'Header Cell Address' without '$' signs
          sAddress = r.Address(False, False)
        
          'Get the 'AutoFilter' criteria for that column
          sCriteria = GetAutoFilterCriteria(r)
      
          'Add to the output string
          s = sAddress & ":" & sCriteria
          sData = sData & s & vbCrLf
        Next r
      End If
      
      MsgBox sData
      
      'Clear object pointers
      Set r = Nothing
      Set ws = Nothing
    End Sub
    
    Function GetAutoFilterRangeAddress(ws As Worksheet) As String
      'This gets the address of the Active Autofilter on a given Worksheet
    
      Dim r As Range
      
      If ws.AutoFilterMode = True Then
        Set r = ws.AutoFilter.Range
        GetAutoFilterRangeAddress = r.Address(False, False)
        Set r = Nothing
      End If
      
    End Function
    
    Function GetAutoFilterHeaderRangeAddress(ws As Worksheet) As String
      'This gets the address of the Active Autofilter on a given Worksheet
      '
      'Null String is returned if there is no 'Active AutoFilter'
      '
      'It is the calling routine's responsibility to make sure the Sheet Exists
      '
      'The 'Header Range' is the interesection of the 'AutoFilter Range' with the 'Entire Header Row'
    
      Dim myHeaderRange As Range
      Dim r1 As Range
      Dim r2 As Range
      Dim iHeaderRow As Long
      
      If ws.AutoFilterMode = True Then
        
        Set r1 = ws.AutoFilter.Range
        iHeaderRow = r1.Row
        Set r2 = ws.Range(ws.Rows(iHeaderRow), ws.Rows(iHeaderRow)).Rows
        Set myHeaderRange = Intersect(r1, r2)
        GetAutoFilterHeaderRangeAddress = myHeaderRange.Address(False, False)
        
        Set r1 = Nothing
        Set r2 = Nothing
        Set myHeaderRange = Nothing
      End If
    
    End Function

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Displaying all Applied Filters

    Hi, welch1198,

    also important is that I also need to know the order the filters are applied?
    AFAIK no chance except you place a range where the filter range and criteria is listed in the order it should be applied (but why then would you need to know what filters are on?) or maybe try the Advanced Filter instead.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Registered User
    Join Date
    07-30-2014
    Location
    LI, NY
    MS-Off Ver
    2010
    Posts
    5

    Re: Displaying all Applied Filters

    Thank you both very much, Lewis this is great and we really don't use a filter for more than two items per column so this will work well. The dates not formatting in the filter I will try to play with. Holger, the why is because some of the spreadsheets we have are very long and have many columns (I believe through column "mm" at this time), if we only had a few columns would be silly to try to work to get this. The Business Analyst is looking for a quick way to see what the filters are and what was chosen - in what order - so she can make sure the reporting is accurate when switching criteria. Currently she removes all of the filters she has set and redoes them. If she knew from the previous weeks reporting where the filtering was left off (as an example) it would just help make her life easier. Thanks again to both of you I really appreciate the replies.

  5. #5
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Displaying all Applied Filters

    The following may help you with date conversion:
    Sub ConvertDoubleToDate()
    
      Const ThisMorning As Double = 41884.4146643519
      
      MsgBox Format(ThisMorning, "mmm d, yyyy h:mm:ss AM/PM")
    
    End Sub
    Lewis

  6. #6
    Registered User
    Join Date
    07-30-2014
    Location
    LI, NY
    MS-Off Ver
    2010
    Posts
    5

    Re: Displaying all Applied Filters

    Lewis, you're terrific thank you! I will try this today. Have a terrific rest of your day!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Apply 'X only to records that has Filters applied
    By nironto in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-09-2013, 07:07 AM
  2. [SOLVED] Averaging data from column with filters applied..
    By mungel in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-25-2013, 01:02 PM
  3. Saving Database with Filters Applied?
    By cmf0106 in forum Access Tables & Databases
    Replies: 4
    Last Post: 11-04-2012, 07:33 AM
  4. Applied filters from specific cells
    By kevin_wvu in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-01-2011, 08:41 AM
  5. Possible to save a spreadsheet with filters applied?
    By notoriouscwe in forum Excel General
    Replies: 2
    Last Post: 06-25-2010, 08:13 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1