+ Reply to Thread
Results 1 to 7 of 7

Call macro when filter is applied?

  1. #1
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Call macro when filter is applied?

    Is it possible to kick off a macro when a filter is applied? User will have about 10 columns of data, and would like to call specific macros when each of these columns are filtered. The sheet doesn't exist yet - so I suppose this is more of a theoretical question

    Thanks for any input!
    Last edited by JP Romano; 06-24-2011 at 07:57 AM. Reason: solved

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,445

    Re: Call macro when filter is applied?

    Hi JP Romano,

    If the filter is applied uising a Table and the top row of the table doesn't move, you can use Event Macros to trigger a macro.

    Say the Table Filters are from A1 to H1.

    Code behind the Worksheet that would look like this:
    Please Login or Register  to view this content.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Call macro when filter is applied?

    Hi JP,

    There isn't a specific event trigger for using the AutoFilter, however you could try using the Worksheet_Calculate event if your table has formulas in it. If there are no formulas, in an unused cell just put the =NOW() function, which will force a recalc every time you change the filter(s).

    JP Gonzalez has a thread to determine which column is filtered here: http://www.mrexcel.com/forum/showthread.php?p=664446

    So in the Worksheet_Calculate event you could use that code to check which column is filtered, and then call the appropriate macro.

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Call macro when filter is applied?

    Marvin, if I'm not mistaken, applying a filter to a column does not change the activecell, therefore that event is not triggered.

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,445

    Re: Call macro when filter is applied?

    Paul,

    You are absolutely correct. But to live up to my signature line, find the attached that shows how to test that.

    I hope the attached will allow the OP to discover how to test triggers. AND I was wrong about applying a Filter triggering an event.
    Attached Files Attached Files

  6. #6
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Re: Call macro when filter is applied?

    Unfortunately, there are no calculations anywhere on the sheet. However, you did just give me the idea to add a subtotal(counta) formula, to the sheet.. then whenever a filter is applied, that count will change, and I can kick something off when that cell changes.
    Thanks all!!!!!

  7. #7
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Re: Call macro when filter is applied?

    Paul, don't know how I missed your solution with the "NOW()" entry... that'll do it!

+ 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