+ Reply to Thread
Results 1 to 22 of 22

how can I create a macro which will check the selected criteria in filter?

  1. #1
    Registered User
    Join Date
    10-20-2012
    Location
    Houston, TX USA
    MS-Off Ver
    Excel 2007
    Posts
    47

    Question how can I create a macro which will check the selected criteria in filter?

    I want to create a macro which will check selected criteria in filter, how would i do that?

    can any one provide me an example?

    Thanks,
    Anand

  2. #2
    Forum Contributor jimmalk's Avatar
    Join Date
    08-31-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: how can I create a macro which will check the selected criteria in filter?

    Hi Anand. Try this:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Put this into a cell : FilterCriteria(# of columns in your table, Table Header row)

    Where (# of columns in your table) is how many columns you have in your table.
    And (Table Header row) is the row number that the table header is in.


    Now as you change the filter in your table, the filter criteria will appear in the cell with the FilterCriteria() function.

    Have a button on your page with the name "ClearFilter". Attach this code to the button :
    Please Login or Register  to view this content.
    Pressing the button will clear the filter from your table.
    Last edited by jimmalk; 11-04-2012 at 11:26 PM.

  3. #3
    Registered User
    Join Date
    10-20-2012
    Location
    Houston, TX USA
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: how can I create a macro which will check the selected criteria in filter?

    Thanks Jim, this code works partially.

    It does not work in two scenario,

    Scenario 1: When we select all, function does not show any output

    Scenario 2: when first criteria of filter is not selected and if we select 2nd and 3rd criteria, then function does not show any output.

    Any suggestion?

  4. #4
    Forum Contributor jimmalk's Avatar
    Join Date
    08-31-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: how can I create a macro which will check the selected criteria in filter?

    Scenerio 1 : Yes, it is correct that the cell will show nothing. There is no filter to show. If you would like to show something you could replace FilterCriteria = "" with FilterCriteria = "Table Not Filtered"

    Scenerio 2 : I'm not sure. I use the dropdown buttons to select the filter one at a time. I suppose you are applying a filter to several criteria at one time. I have to look into that.. give me a few minutes

  5. #5
    Forum Contributor jimmalk's Avatar
    Join Date
    08-31-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: how can I create a macro which will check the selected criteria in filter?

    Look over the attached file. In the Sub Workbook_Open(), comment out the line "Application.Calculation = xlManual" or set it to xlAutomatic... Should work like you want now. It has an additional capability to right click on any cell to apply a filter. This code does work with multiple criteria, maybe you need to adapt it a little to work with your table? But it should work. Please post back if not.
    Attached Files Attached Files
    Last edited by jimmalk; 11-04-2012 at 11:53 PM.

  6. #6
    Registered User
    Join Date
    10-20-2012
    Location
    Houston, TX USA
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: how can I create a macro which will check the selected criteria in filter?

    let me try this and I will post if it works or not, Thanks!

  7. #7
    Registered User
    Join Date
    10-20-2012
    Location
    Houston, TX USA
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: how can I create a macro which will check the selected criteria in filter?

    It looks like I am missing something here, in above spreadsheet, I have unlocked it and wrote a function "=FilterCriteria(5,5)" in cell Q5, and it does not show any value of filter criteria even if I have one criteria selected. any suggestion?

  8. #8
    Forum Contributor jimmalk's Avatar
    Join Date
    08-31-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: how can I create a macro which will check the selected criteria in filter?

    You should put into the Q5 (or any other cell you want) "=FilterCriteria(8,5)" ... because there are 8 columns in the table, and the table header is in row 5

    Remember also ... in the Sub Workbook_Open(), comment out the line "Application.Calculation = xlManual" or set it to xlAutomatic
    Last edited by jimmalk; 11-05-2012 at 12:09 AM.

  9. #9
    Registered User
    Join Date
    10-20-2012
    Location
    Houston, TX USA
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: how can I create a macro which will check the selected criteria in filter?

    Still it does not show anything, I only have one filter criteria selected which is one animal name.

  10. #10
    Forum Contributor jimmalk's Avatar
    Join Date
    08-31-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: how can I create a macro which will check the selected criteria in filter?

    Is your sheet set to auto-calculate? Did you comment out the line "Application.Calculation = xlManual in Sub Workbook_Open() ? When you put "=FilterCriteria(8,5)" into cell Q5, was that cell set to General (otherwise it will think the code is text)? Cant think of anything else.

    Try..
    Clear the filter on the Table
    Right click on any cell to activate the filter
    Repeat right clicks on any other fields
    This should show the filter criteria in the cell where you placed FilterCriteria().
    Also you can use the built in Excel buttons on the header row of the table to change the filter

  11. #11
    Registered User
    Join Date
    10-20-2012
    Location
    Houston, TX USA
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: how can I create a macro which will check the selected criteria in filter?

    check the attached spreadsheet, it still does not show any thing in cell "Q5".
    Attached Files Attached Files

  12. #12
    Forum Contributor jimmalk's Avatar
    Join Date
    08-31-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: how can I create a macro which will check the selected criteria in filter?

    2 problems you're having. First, you have the file saved with the worksheet calculation set to manual, it must be set to automatic. In the Sub Workbook_Open() put in this line :
    Please Login or Register  to view this content.
    Second problem is that Q5 is on the right and maybe you can't see it. Go into Excel Options and activate the scrollbars, then you can see Q5. I have "=FilterCriteria(8,5)" above the table in cell B2
    Last edited by jimmalk; 11-05-2012 at 01:11 AM.

  13. #13
    Registered User
    Join Date
    10-20-2012
    Location
    Houston, TX USA
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: how can I create a macro which will check the selected criteria in filter?

    Thank you, I think I will spend some time on this and let you know by tomorrow if I have any more questions, Thanks!

  14. #14
    Forum Contributor jimmalk's Avatar
    Join Date
    08-31-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: how can I create a macro which will check the selected criteria in filter?

    You're welcome Anand. I'll watch the post. Good luck

  15. #15
    Registered User
    Join Date
    10-20-2012
    Location
    Houston, TX USA
    MS-Off Ver
    Excel 2007
    Posts
    47

    Question Re: how can I create a macro which will check the selected criteria in filter?

    Here is the file that includes worksheet calculation to Automatic still cell "B2" does not update if I choose some filter criteria in column name "Animal name".

    Any suggestion on what am I missing?

    Thanks!
    Attached Files Attached Files

  16. #16
    Forum Contributor jimmalk's Avatar
    Join Date
    08-31-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: how can I create a macro which will check the selected criteria in filter?

    Hi Anand. The file you posted is fine, should work. The only thing I can think of is that you dont have macros enabled. Make sure you enable macros so the vba code can run

  17. #17
    Registered User
    Join Date
    10-20-2012
    Location
    Houston, TX USA
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: how can I create a macro which will check the selected criteria in filter?

    well the problem is cell "B2" shows value when I right click on any cell inside table but instead if I choose filter criteria manually then it does not update the cell "B2". I checked and Macro is enabled .


  18. #18
    Forum Contributor jimmalk's Avatar
    Join Date
    08-31-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: how can I create a macro which will check the selected criteria in filter?

    The last file you posted is working fine. The only way that B2 would not update would be if you placed the calculation mode back into manual. Look in the "Formulas" tab, make sure that "Calculation Options" is set to "Automatic". Should work.

  19. #19
    Registered User
    Join Date
    10-20-2012
    Location
    Houston, TX USA
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: how can I create a macro which will check the selected criteria in filter?

    I did check it and "Calculation Options" is set to "Automatic". any other ideas?

  20. #20
    Forum Contributor jimmalk's Avatar
    Join Date
    08-31-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: how can I create a macro which will check the selected criteria in filter?

    The last file you re-posted works fine. Maybe you unproected the file, and then re-protected it without selecting "Sort" and "Use Autofilter"? The "Sort" and "Use Autofilter" must be checked to use the built-in table filter controls. Other than having "Calculation Options" set to "Automatic" there really cant be anything wrong. Check again the file you last posted and try using that file, maybe by accident you made some change to the vba code and thats why it isnt working now.

  21. #21
    Registered User
    Join Date
    10-20-2012
    Location
    Houston, TX USA
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: how can I create a macro which will check the selected criteria in filter?

    Jim, you are right, I looked into that file again and it works fine, so it looks like I did something to break it.

    Thank you!

  22. #22
    Forum Contributor jimmalk's Avatar
    Join Date
    08-31-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: how can I create a macro which will check the selected criteria in filter?

    Glad to help Anand. If you found my solution helpful to you, kindly click the star on the helpful posts to give me rep points. Also mark this thread as solved. Good luck

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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