+ Reply to Thread
Results 1 to 17 of 17

Problems with "homemade" autofilter buttons

  1. #1
    Registered User
    Join Date
    05-10-2012
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    15

    Problems with "homemade" autofilter buttons

    I've got a spreadsheet in my Excel 2010 workbork with a lot of data. This page can be sorted by the build in autofilter. On another sheet I have made a button which do some of the sorting. FX:

    Please Login or Register  to view this content.
    When I do this the sheet shows the second quarter of the year. I've got a button which show the third quarter of the year which looks like this:

    Please Login or Register  to view this content.
    My problem is: When I press the first button (Second quarter) it filters and show the second quarter. But when I press the "Third Quarter" button it removes the Second Quarter filter and views only the Third Quarter.

    Is it possible to write some kind of VBA code which make it possible to have both button pressed at the same time, like it's possible to do with the build in autofilter buttons?

    If you're not quite sure what I mean, please ask for better explanation.

    Thanks in advance
    Last edited by CenaDK; 05-22-2012 at 06:51 AM.

  2. #2
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: Problems with "homemade" autofilter buttons

    To view both the quarter together and in assending order use this code.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-10-2012
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Problems with "homemade" autofilter buttons

    Quote Originally Posted by kvsrinivasamurthy View Post
    To view both the quarter together and in assending order use this code.

    Please Login or Register  to view this content.

    Thanks for the fast reply. Maybe I was not quite clear on what i want.
    I want buttons named "Qaurter 1", "Qaurter 2", "Qaurter 3" and "Qaurter 4". I want to make it possible to push the "Qaurter 1" and "Qaurter 3" button, and then only show these 2 quarters.

    At the moment if I press 2 buttons, it will only view the last prest button fx. Quarter 4.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Problems with "homemade" autofilter buttons

    what should happen if you press three buttons?
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  5. #5
    Registered User
    Join Date
    05-10-2012
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Problems with "homemade" autofilter buttons

    Quote Originally Posted by JosephP View Post
    what should happen if you press three buttons?
    I want to show the 3 selected on my sheet?

    Imagine you got:
    january
    february
    march
    april
    may
    etc

    On the autofilter you can select january, march and may with checkboxes.
    I want to make a "feature" like this, where you can press 2 buttons which shows the pressed buttons criteria.

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Problems with "homemade" autofilter buttons

    figured you'd say that - makes it harder ;-)
    can you post a sample of the data you are using? the code will have to be quite specific since Excel's own autofilters couldn't do what you want.

  7. #7
    Registered User
    Join Date
    05-10-2012
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Problems with "homemade" autofilter buttons

    Quote Originally Posted by JosephP View Post
    figured you'd say that - makes it harder ;-)
    can you post a sample of the data you are using? the code will have to be quite specific since Excel's own autofilters couldn't do what you want.
    Yes I will try that tomorrow since I'm not at my workstation atm I will make a simple example to make it easier to understand.
    The last thing i tried was to bind some text strings to the buttons, and by IF sentences push them into the autofilter and see if that's possible.

    The main problem is I want to make a "grocery list" with selections, and then send them away at the same time. It would be a lot easier of i know to commands a prior.

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Problems with "homemade" autofilter buttons

    I reckon you're probably going to need to filter with an array of values to get what you need instead of using greater than and less than criteria.

  9. #9
    Registered User
    Join Date
    05-10-2012
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Problems with "homemade" autofilter buttons

    Quote Originally Posted by JosephP View Post
    I reckon you're probably going to need to filter with an array of values to get what you need instead of using greater than and less than criteria.
    Even though i know that I only got 4 different buttons?

    It must be possible to do with IF sentences? There must be a way to check what filter is on, and then choose another?

  10. #10
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Problems with "homemade" autofilter buttons

    until I see your data I'm just a-guessing. :-) since you can only really have two ranges (if your example relates to your actual data) then yeah you probably can do it with a built-in autofilter and it may be easier than arrays.

    most anything is possible - doesn't always make it right or the best way though.

  11. #11
    Registered User
    Join Date
    05-10-2012
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Problems with "homemade" autofilter buttons

    I've made an attachment now with some data.

    At the moment you can push a button and it shows the correct data. I want to make it possible to push 2 buttons and show the data from both criterias.

    Test_Autofilter.xlsm

  12. #12
    Registered User
    Join Date
    05-10-2012
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Problems with "homemade" autofilter buttons

    I kind of found a solution but it will take 64 if statemens (4^2) which is not usefull and 2 complicated. So i really hope someone got a better solution

  13. #13
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Problems with "homemade" autofilter buttons

    I'd use an advanced filter and some checkboxes like this.
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    05-10-2012
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Problems with "homemade" autofilter buttons

    Quote Originally Posted by JosephP View Post
    I'd use an advanced filter and some checkboxes like this.
    That's actually a very good solution. How did you make that? It looks pretty simple.

    Is there more than the code in K2 and the setFilters and clear in VBE?

  15. #15
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Problems with "homemade" autofilter buttons

    there's a formula in J2 that looks at which checkboxes have been set (the checkboxes are linked to the cells under them but those cells are formatted to hide all data) but other than that it's just the criteria range and the code you see.

  16. #16
    Registered User
    Join Date
    05-10-2012
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Problems with "homemade" autofilter buttons

    Quote Originally Posted by JosephP View Post
    there's a formula in J2 that looks at which checkboxes have been set (the checkboxes are linked to the cells under them but those cells are formatted to hide all data) but other than that it's just the criteria range and the code you see.
    Thank you. I will use this solution i think

  17. #17
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Problems with "homemade" autofilter buttons

    you're welcome-glad I could help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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