+ Reply to Thread
Results 1 to 2 of 2

AutoFilter toggling in VBA (How to use correctly)

  1. #1
    Dennis
    Guest

    AutoFilter toggling in VBA (How to use correctly)

    XL 2003

    In VBA I calculate a range (myRange) to apply in an autofilter.

    I have used both of the following code and the AutoFilter toggles on to off
    each time I run the code. My goal is to have the VBA code remove all
    previous settings then apply
    AutoFilter to myRange. Therefore I tried to clear settings:

    Selection.AutoFilter -or- ActiveSheet.UsedRange.AutoFilter

    Later in the same procedure I used:

    If myRange.AutoFilter Then myRange.AutoFilter

    -or-

    myRange.AutoFilter

    No matter what my approach, the AutoFilter toggles on to off
    each time I run the procedure.

    Where is my logic breaking down?

    Dennis

  2. #2
    Norman Jones
    Guest

    Re: AutoFilter toggling in VBA (How to use correctly)

    Hi Dennis,

    Try something like:

    Sub Tester()
    With ActiveSheet
    If .AutoFilterMode Then
    If .FilterMode Then .ShowAllData
    Else
    .Range("A1").AutoFilter
    End If
    End With
    End Sub

    ---
    Regards,
    Norman



    "Dennis" <[email protected]> wrote in message
    news:[email protected]...
    > XL 2003
    >
    > In VBA I calculate a range (myRange) to apply in an autofilter.
    >
    > I have used both of the following code and the AutoFilter toggles on to
    > off
    > each time I run the code. My goal is to have the VBA code remove all
    > previous settings then apply
    > AutoFilter to myRange. Therefore I tried to clear settings:
    >
    > Selection.AutoFilter -or- ActiveSheet.UsedRange.AutoFilter
    >
    > Later in the same procedure I used:
    >
    > If myRange.AutoFilter Then myRange.AutoFilter
    >
    > -or-
    >
    > myRange.AutoFilter
    >
    > No matter what my approach, the AutoFilter toggles on to off
    > each time I run the procedure.
    >
    > Where is my logic breaking down?
    >
    > Dennis




+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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