Forum Discussion
MeloNnadi
Mar 08, 2024Copper Contributor
Microsoft Project VBA code to clear all applied filters
Please I need help with writing a VBA code (Macro) on Microsoft Project that will clear/remove all applied filters in a schedule. Thank you.
MeloNnadi
Mar 08, 2024Copper Contributor
John-project no John I'm not referring to just auto filter, that is easy to clear if you just have one filter by choosing no filter from the drop down. To clarify, i meant a situation where you have applied more than one filter (auto, custom and/or column). A macro that will enable you to clear all of them with one click of that macro (VBA code). I hope it is clearer now what i am looking for. Thank you so much.
MeloNnadi
Mar 08, 2024Copper Contributor
In addition, also in a situation that one applies a filter and forgets or you receive a schedule from a colleague and want to be sure that any applied filter is cleared, you can just run the same macro to clear any applied filter instead of taking time to search for which filter is applied. Thank you.
- John-projectMar 09, 2024Silver ContributorMeloNnadi,
Did you actually try my suggestion? If you did you would see the result does what you want and it is a very simply line of code
Sub Macro1()
' Macro Macro1
' Macro Recorded 3/8/24 by John.
FilterApply Name:="All Tasks"
End Sub
By the way, you mentioned more than one filter "(auto, custom and/or column)". What is a column filter?
John- MeloNnadiMar 09, 2024Copper ContributorThanks so much John. I have tried the above code and it works. By column filter i just meant the filter option on column headers. You get to it by clicking on the drop down arrow next to the column header.
- John-projectMar 09, 2024Silver ContributorMeloNnadi,
You;re welcome and thanks for the feedback.
What you call the "column filter" is actually the auto-filter.
Since your goal is to "clear" a file of any attributes that may be applied, may I suggest you also clear any grouping and sorting. In some of my macros, I save those attributes (view, filter, group, etc.) in variables at the beginning so I can work with an unencumbered file as the macro processes. Then, when the macro finishes doing it's thing, I return the file to it's original state from the saved attribute variables. Of course, none of this is necessary if the macro runs exclusively using background processing (i.e. operates directly on Project's objects independent of how the plan is displayed).
John