Consulting

Results 1 to 9 of 9

Thread: Autofilter Issue

  1. #1

    Angry Autofilter Issue

    Hi All,

    I need help with an Autofilter issue I cannot tie down. I want to check the state of the autofilter to see whether it is on or not and applied. If it applied do nothing. If it isn't apply it:

        If Worksheets("Sheet1").FilterMode = True Then 
            Else 
    Selection.Autofilter   
    End If
    Whenever I check the state of Worksheets("Sheet1").FilterMode in the Immediate window it is always false regardless of whether the autofilter is applied or not

    The first time through the code if the autofilter is already applied it will be removed. The second time through the code if the autofilter is not applied it is added!!

    I cant understand what the problem is??

    any help greatly appreciated

    thanks,

    Paddy

  2. #2
    VBAX Contributor GarysStudent's Avatar
    Joined
    Aug 2012
    Location
    Lakehurst, NJ, USA
    Posts
    127
    Location
    There is a difference between FilterMode and AutoFilterMode. Once you have switched on an AutoFilter and the drop-downs are visible, AutoFilterMode will become True. If then actually use the drop-downs to activate the filter, FilterMode will also become True!
    Have a Great Day!

  3. #3
    Hi,

    I have changed this to the following and still have the same problem:

     If Worksheets("Sheet1").AutoFilterMode = True Then
            Else
    Selection.AutoFilter
    End If
    If the autofilter is on it is turned off. If the autofilter is off it is turned on. I just need it to recognise if the autofilter is on the keep it on. If off then turn it on.

    The Else portion of the code is fired regardless of whether then autofilter is on or not...

    Investigating this further I have tried the code on a normal header and it works fine. The problem is when using this on the header of a Table. The Table name is "Avail_Incidents". Is there a way round this for Table autofilters?

    thanks,

    paddy.

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    1. Where is the code? In a sheet's code module, or a standard code-module.. or somewhere else?
    2. Are you sure that the sheet which is active at the time you run the code is actually Sheet1 ?!
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    Quote Originally Posted by p45cal View Post
    1. Where is the code? In a sheet's code module, or a standard code-module.. or somewhere else?
    2. Are you sure that the sheet which is active at the time you run the code is actually Sheet1 ?!
    Hi, the full code is:

        Sheets("Sheet1").Select
        
     If Worksheets("Sheet1").AutoFilterMode = True Then
            Else
    Selection.AutoFilter
    End If

  6. #6
    in a standard code-module. As shown before the autofilter needs to be applied to the header of the table on sheet1

  7. #7
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    …and point 2 in msg#4 above?
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  8. #8
    Try the above code...

  9. #9
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Are you using a Table rather than a regular range?
    Be as you wish to seem

Posting Permissions

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