+ Reply to Thread
Results 1 to 17 of 17

Toggle filters on & off

  1. #1
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Toggle filters on & off

    Hi

    Using a button, is there a way to toggle the filters on & off, for the following code ...

    Much appreciated

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Toggle filters on & off

    Can you provide a copy of the workbook ?

    Thanks

  3. #3
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Toggle filters on & off

    Hi fredlo2010

    It's huge, has 25+ tabs. As you can see by the code above!

    Basically, have a filter that on each tab mostly in Col D which filters to show "Blank" rows. The options in the Filter are "Zero" or Blank.
    So, aim of filter is to remove rows where all values = Zero... hence choosing Blank in the code.

    Want a button when pressed will show Blank and then prsess again will clear the filter

    HTH

  4. #4
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Toggle filters on & off

    OR ...

    Is there a better way to write the code I have here?

    Thx

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Toggle filters on & off

    Hi, kaseyleigh,

    maybe like this:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  6. #6
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Toggle filters on & off

    Cool! Thank you! Holger

    Will need to move the filter to Col D on all sheets so yr code will work

    I will now go and learn what each line in your code means and does

    Thank you once again!!

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Toggle filters on & off

    Hi, kaseyleigh,

    sorry I missed that part. It could be handled by a second Array:

    Please Login or Register  to view this content.
    Ciao,
    Holger

  8. #8
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Toggle filters on & off

    Good job

  9. #9
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Toggle filters on & off

    Hey Holger!

    Thank you so much!

    I am a novice at writing code so love learning

    Thank you once again!! Have a lovely day in Hamburg

  10. #10
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Toggle filters on & off

    Morning Holger,

    May I ask for your assistance once again?

    I'd like to add to the code, when saving the file to PDF ALL wSheets must have the filter enabled to .AutoFilter Field:=1, Criteria1:="="

    PROBLEM : If a User cleared the filter on one wSheet and enabled on another, I am going to have some inconsistency. I thought about hiding the filter columns (easy solution) but then your code wouldn't work

    I'll be very grateful for your help

    Thanks

  11. #11
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Toggle filters on & off

    Hi, kaseyleigh,

    this code takes the AufoIlterMode from the first worksheet of the array and toggles the state. If you want to make sure that the filters are turned on you should assign True to the variable blnFilterOn.

    Please Login or Register  to view this content.
    The case of turning the Filter into a wanted mode could be asserted by passing a variable as a pamaeter or using a global variabl or by using a modified code for the PDF.

    Ciao,
    Holger

  12. #12
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Toggle filters on & off

    Wow! I'm afraid you lost me in the jargon a relative newbie to VBA.

    If I wanted to Hide all the filter columns in the wSheets, how would your code Sub FilterOutZeros_2() cope with that?

    Many thanks

  13. #13
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Toggle filters on & off

    Hi, kaseyleigh,

    you would need to rewrite the code asit checks for teh individual setting of Autofilter whereas 3 takes the code from the first sheet and toggles that throughout. Maybe you should consider an extra worksheet where you may have the names of the worksheets, the columns to filter and the status (you wouldnīt need the arrays) and work that over in one look and convert the status being stated there.

    Ciao,
    Holger

  14. #14
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Toggle filters on & off

    OK, I think that will be better to add another ws.

    How do I add a status of the filter? and how would it change if filter was On or Off? Is there a function I am unaware of?

    Thank you!

  15. #15
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Toggle filters on & off

    Hi, kaseyleigh,

    inside the code UI supplied itīs checked to see if a sheet features the filter which could be used to do as you request. This would return either TRUE if used or FLASE if not. That could be simply reverted by
    Please Login or Register  to view this content.
    from TRUE to FLASE and reverse. You may use a cell for each sheet individually or one for the total of the sheets.

    Ciao,
    Holger

  16. #16
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Toggle filters on & off

    Hey thanks!

    I managed to come up with a solution (miracles) see below ..

    Please Login or Register  to view this content.
    Thanks for all your advice!

  17. #17
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Toggle filters on & off

    Any ideas on how to deactivate the Save button?
    OR
    should I open a new thread?

    Much appreciated,
    K

+ 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. 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
  3. Replies: 4
    Last Post: 07-24-2012, 01:21 PM
  4. How to toggle
    By pwsurfer in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-27-2010, 02:32 PM
  5. [SOLVED] Toggle between worksheets
    By Gary S. in forum Excel General
    Replies: 2
    Last Post: 03-01-2006, 12:25 PM

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