Consulting

Results 1 to 4 of 4

Thread: Solved: Autofilter

  1. #1

    Solved: Autofilter

    Hi,

    Any ideas how i go in and automatically either remove all filters from tabs or add filters to all tabs in a workbook regardless of whether there are already existing filters or not?

    Selection.autofilter either adds or removes a filter but does not distinguish between a filter already being there.

    for example if i run a macro to autofilter a tab but someone else has left a filter already on it - my running selection.autofilter will remove the filter and leave none there.

    Any idea how i can go through a workbook and
    1: identift if there is a filter on the tab
    2: on the back of this, then either add or remove existing filter.

    I am completely stumped with this one sorry!!!

    Sarah

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    [VBA]Sub CheckAutoFilters()
    Dim lngSheet As Long
    For lngSheet = 1 To Sheets.Count
    Debug.Print Worksheets(lngSheet).Name, Worksheets(lngSheet).AutoFilterMode
    Next lngSheet
    End Sub
    [/VBA]

  3. #3
    VBAX Tutor
    Joined
    Feb 2006
    Posts
    295
    Location
    something like this works for me
    [vba]If ActiveSheet.AutoFilterMode Then
    ActiveSheet.AutoFilterMode = False
    Else
    ActiveSheet.Range("A3").AutoFilter
    End If
    [/vba]

  4. #4
    That is just the answer thanks for that!!

    Apologies for not getting back sooner.

    Sarah



    Quote Originally Posted by vzachin
    something like this works for me
    [vba]If ActiveSheet.AutoFilterMode Then
    ActiveSheet.AutoFilterMode = False
    Else
    ActiveSheet.Range("A3").AutoFilter
    End If
    [/vba]

Posting Permissions

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