+ Reply to Thread
Results 1 to 18 of 18

Reapply all filters on workbook open

  1. #1
    Registered User
    Join Date
    10-18-2022
    Location
    London, England
    MS-Off Ver
    365
    Posts
    19

    Reapply all filters on workbook open

    Hello,

    Have this problem whereby users are leaving filters applied in a workbook with multiple sheets.

    This means that other users are opening the workbook and are unable to find data when they don't realise a filter has been applied.

    Problem is, this workbook can be open by many users at one time, so a macro that clears and reapplies all filters when the workbook is opened would then clear filters for other users already in the workbook?

    If this is not the case, is someone able to help me edit the below code to include "clear all filters on all sheets" then "reapply all filters on all sheets" when the workbook is opened?

    Please Login or Register  to view this content.
    Many Thanks
    Slowly learning Visual Basic for Applications

  2. #2
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: Reapply all filters on workbook open

    The line:
    Please Login or Register  to view this content.
    Will remove all selections from the filter but leave the filter applied to the data.

    If there are no items filtered in the data then the above will result in an error so one workaround might be:
    Please Login or Register  to view this content.
    If things don't change they stay the same

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Reapply all filters on workbook open


    As a reminder On Error is useless just checking the worksheet property FilterMode

  4. #4
    Registered User
    Join Date
    10-18-2022
    Location
    London, England
    MS-Off Ver
    365
    Posts
    19

    Re: Reapply all filters on workbook open

    Hello,

    Thanks for your reply. Think I may not have been clear in what I was asking.

    When the user opens the workbook, the code should basically clear all the filters on all sheets so that nothing is hidden by a filter (or filtered out) on any sheet but ensure that the filter arrows are there in the header row so that they can use them to filter.

    I found the below code which works when I assign it to a macro button, but I'd like similar to this to happen when the workbook is opened. I have no idea how to add the below into my original piece of code

    Please Login or Register  to view this content.

  5. #5
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: Reapply all filters on workbook open

    Mark L: Not in this instance, if you create a table with a filter on and dont filter anything then:
    Please Login or Register  to view this content.
    Will return an error

    However wrapped in the suggested On Error statement it will not error due to the resume next part of the statement.

    On Error is not "Useless" in the given example, i agree there are other ways to get around the issue hence the use of the words "one workaround might be"

  6. #6
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: Reapply all filters on workbook open

    Quote Originally Posted by Chris_M_1987 View Post
    When the user opens the workbook, the code should basically clear all the filters on all sheets so that nothing is hidden by a filter (or filtered out) on any sheet but ensure that the filter arrows are there in the header row so that they can use them to filter.
    That is what the below line is doing but to one sheet (remove all selections from filter but leave filter in tact):
    Please Login or Register  to view this content.

  7. #7
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: Reapply all filters on workbook open

    You could try and paste the below into the ThisWorkbook code module:
    Please Login or Register  to view this content.
    Or without On Error:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-18-2022
    Location
    London, England
    MS-Off Ver
    365
    Posts
    19

    Re: Reapply all filters on workbook open

    Basically if I add the new bit of code to the bottom of my original code, it only clears the filters on some sheets. It doesn't work on 2 out of the 8 sheets on the workbook.

    I'm not an advanced user and am relying on code created by other people.

    Please Login or Register  to view this content.

  9. #9
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: Reapply all filters on workbook open

    Maybe try your code like the below:
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    10-18-2022
    Location
    London, England
    MS-Off Ver
    365
    Posts
    19

    Re: Reapply all filters on workbook open

    Run-time error '1004':

    ShowAllData method of Worksheet class failed

  11. #11
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,963

    Re: Reapply all filters on workbook open

    Try removing anything to do with clearing the filters from the workbook open event. Then put the ExtendOffice code as separate sub and call it from the open event.


    Please Login or Register  to view this content.

  12. #12
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Reapply all filters on workbook open


    Quote Originally Posted by CheeseSandwich View Post
    Mark L: Not in this instance, if you create a table with a filter on and dont filter anything then:
    Ok with Excel tables …

  13. #13
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: Reapply all filters on workbook open

    Marc L: I do apologise for the mistake in your name, it wasn't intentional.

  14. #14
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Post Re: Reapply all filters on workbook open


    I know, no offense, common mistake, no problemo !

  15. #15
    Registered User
    Join Date
    10-18-2022
    Location
    London, England
    MS-Off Ver
    365
    Posts
    19

    Re: Reapply all filters on workbook open

    Hi There

    It's still not working on some sheets but I think I know why.

    These sheets are protected, as they can't be accidentally overwritten. The sheet names are:

    Master Data
    Occasions Current 6 Months
    Occasions Last 12 Months

    Is there a way to remove the protection from these sheets, run the filter code and then reapply the protection (with the same settings)?

    Please Login or Register  to view this content.
    Kind Regards
    Last edited by Chris_M_1987; 11-23-2022 at 07:26 AM.

  16. #16
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,963

    Re: Reapply all filters on workbook open

    What if you allow the autofilter when protecting the sheets by ticking "Use Autofilter", then change the Clear_fiter code to

    Please Login or Register  to view this content.
    Last edited by ByteMarks; 11-23-2022 at 08:09 AM.

  17. #17
    Registered User
    Join Date
    10-18-2022
    Location
    London, England
    MS-Off Ver
    365
    Posts
    19

    Re: Reapply all filters on workbook open

    That's not worked either unfortunately.

    I checked and autofilter was ticked on all the protected sheets.

  18. #18
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,963

    Re: Reapply all filters on workbook open

    Did you manually unprotect and re-protect the sheets enabling use of the auto filter?

+ 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. Clear all filters and then reapply filter for the number 1
    By wherdzik in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-16-2020, 05:46 PM
  2. Workbook Open - Refresh Filters in Table
    By jharvey87 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2018, 12:53 PM
  3. [SOLVED] Reapply Filters for MULTIPLE tables Automatically
    By CrazyCookie in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-21-2016, 07:30 PM
  4. Replies: 0
    Last Post: 08-30-2012, 04:56 PM
  5. Replies: 4
    Last Post: 07-24-2012, 01:21 PM
  6. Replies: 0
    Last Post: 05-09-2012, 06:09 PM
  7. Save an open workbook, then open template workbook and close the saved workbook
    By ondvirg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-27-2009, 10:20 PM

Tags for this Thread

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