+ Reply to Thread
Results 1 to 12 of 12

Preventing Filters

  1. #1
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Preventing Filters

    Is there vba code that will prevent auto- filters being selected in a worksheet/workbook as I've other macro's that run automatically that don't work well when filters are active.
    Last edited by ScabbyDog; 08-27-2015 at 02:52 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Preventing Filters

    Hello ScabbyDog,

    You can turn auto-filtering off at any time with VBA.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Preventing Filters

    Thanks, but I need code that when someone attempts to turn on AutoFilters on a worksheet, it disables it immediately.

  4. #4
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Preventing Filters

    Any ideas if possible?

  5. #5
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Preventing Filters

    Adding filters doesn't trigger an event that I know of (which you could make use of the run an unfilter macro).... BUT n a nutshell, if you need to prevent the user from doing what they want to the sheet, you just protect the sheet.
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  6. #6
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Preventing Filters

    Quote Originally Posted by GeneralDisarray View Post
    Adding filters doesn't trigger an event that I know of (which you could make use of the run an unfilter macro).... BUT n a nutshell, if you need to prevent the user from doing what they want to the sheet, you just protect the sheet.
    How do you protect the sheet to prevent an autofilter being applied though?

  7. #7
    Forum Contributor
    Join Date
    01-20-2012
    Location
    Amsterdam, The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    186

    Re: Preventing Filters

    it is under View -> Protect Sheet -> Use Autofilter.
    Here you can allow/disallow users to use the Autofilter

  8. #8
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Preventing Filters

    Thanks. How do I put that into vba code though so whenever I run a macro, it disables the protect sheet for AUtoFilter only, and then at the end of the macro, it re-enables it.

  9. #9
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Preventing Filters

    I can use the VBA recorder for that, however when I do this it locks all the cells as well. I just want the AutoFilter to be blocked. Any idea how to alter the below so it does just that?

    Please Login or Register  to view this content.

  10. #10
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Preventing Filters

    Ok - you just need to protect/unprotect at the start and end. I would recommend using a password. Also, you don't have to include all of the options (DrawingObjects:=False, Contents:=True, etc....). You set those manually in the ribbon, one time. When your code re-protects the sheet it will remember the choices you made.

    TO PREVENT FILTERS just protect the sheet (by default, the box for 'Use Autofilter' is unchecked... but if you want to verify that, when you protect the sheet from the ribbon scroll down the list of optional allowed actions to see it).


    Example:

    Please Login or Register  to view this content.

    The most important thing to remember is to set up the worksheet properly so the user can access the areas they should be able to access - and make sure you unprotect/re-protect the sheet in any macro that needs to alter the protected sheet.
    Last edited by GeneralDisarray; 08-28-2015 at 10:22 AM.

  11. #11
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Preventing Filters

    Thanks.

    I want all users to be able to edit everything except use autofilter.

    What should be ticked and unticked in that list so?

  12. #12
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Preventing Filters

    ... check whatever you want them to be able to do ...

    If that is the only thing you want to do, try this:
    • Highlight the cells the user will need to have access to.
    • Right click anywhere in the selected area and select 'Format cells'.
    • Go to the last tab named 'Protection'.
    • Uncheck the first box labeled 'Locked'.
    • Press OK.

    When you lock the sheet, check any of the boxes you want - you can check all of them, except the 'use autofilter' if you like.

    Does that work for you?

+ 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. Replies: 7
    Last Post: 07-15-2019, 03:06 AM
  2. Filters : Not Equals <> with Filters is not working !!!!
    By vishulive in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-04-2015, 01:40 AM
  3. Filter report filters based upon previous report filters!!??
    By jackie_m in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 01-21-2015, 05:17 AM
  4. Pivot Filters to change simulataneously with other pivot filters
    By ScottBeatty in forum Excel Charting & Pivots
    Replies: 9
    Last Post: 07-02-2014, 10:48 AM
  5. Using filters, and then unselecting filters. Organizing data.
    By lesoies in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 08-09-2013, 07:55 AM
  6. Replies: 4
    Last Post: 07-24-2012, 01:21 PM
  7. [SOLVED] preventing duplicates
    By Bonnie in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-02-2005, 11:06 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