+ Reply to Thread
Results 1 to 10 of 10

VBA to Amend the Filter Selection on a Pivot Table Based on a Drop Down List

  1. #1
    Valued Forum Contributor
    Join Date
    09-09-2009
    Location
    Liverpool, England
    MS-Off Ver
    W: 2021 H: 365
    Posts
    940

    VBA to Amend the Filter Selection on a Pivot Table Based on a Drop Down List

    Afternoon all,

    I'm creating a report and I'd like the month filter in the pivot table to dynamically change based on the selection in a drop down list (example attached).

    Thanks in advance.

    Snook

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,919

    Re: VBA to Amend the Filter Selection on a Pivot Table Based on a Drop Down List

    The secret to changing a filter multiselect is that first you have to turn everything "on" and then turn off what you don't want.

    Please Login or Register  to view this content.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Valued Forum Contributor
    Join Date
    09-09-2009
    Location
    Liverpool, England
    MS-Off Ver
    W: 2021 H: 365
    Posts
    940

    Re: VBA to Amend the Filter Selection on a Pivot Table Based on a Drop Down List

    Hi dflak,

    Thanks for this, much appreciated. It's functioning as I would like but it doesn't appear to be selecting the right months.

    Any suggestions?

    Snook

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,919

    Re: VBA to Amend the Filter Selection on a Pivot Table Based on a Drop Down List

    The reason it fails is because Pivot Filters treat numbers and dates as strings. .

    Here is the modified code:
    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    09-09-2009
    Location
    Liverpool, England
    MS-Off Ver
    W: 2021 H: 365
    Posts
    940

    Re: VBA to Amend the Filter Selection on a Pivot Table Based on a Drop Down List

    Magic, cheers dflak. I did try to figure it out myself but what you wrote seemed logical to me so I couldn't see what the problem was?!?!

  6. #6
    Valued Forum Contributor
    Join Date
    09-09-2009
    Location
    Liverpool, England
    MS-Off Ver
    W: 2021 H: 365
    Posts
    940

    Re: VBA to Amend the Filter Selection on a Pivot Table Based on a Drop Down List

    Me again,

    I've been trying to use the solution in my workbook but I'm struggling to apply it to multiple pivot tables.
    I assumed I'd be able to replicate the macro 3 times for each pivot table but that doesn't appear to work.
    I've amended my workbook to better reflect the data I'm working with.

    I'd be grateful if someone could tweak the solution provided above so that it will work with multiple pivot tables.

    Thanks in advance,

    Snook

  7. #7
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,919

    Re: VBA to Amend the Filter Selection on a Pivot Table Based on a Drop Down List

    There is a slightly different plan of attack. This code loops through all the sheets, finds whatever pivot tables are on the sheet and resets the filter. If you add pivot tables that don' use Month No, then this code will break.

  8. #8
    Valued Forum Contributor
    Join Date
    09-09-2009
    Location
    Liverpool, England
    MS-Off Ver
    W: 2021 H: 365
    Posts
    940

    Re: VBA to Amend the Filter Selection on a Pivot Table Based on a Drop Down List

    Cheers dflak, much appreciated!

    Thankfully (at the mo) all the pivot tables use the MonthNo field.

    Thanks again,

    Snook

  9. #9
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,919

    Re: VBA to Amend the Filter Selection on a Pivot Table Based on a Drop Down List

    If you add other pivot tables, then the code would have to be modified. I would recommend telling the spreadsheet what sheets / tables need updating in a table that can be on a hidden sheet. You can loop through the contents of this table to get the sheets and pivot tables by name. The core code - turn everything on and then turn off what you don't need - will remain the same.

  10. #10
    Valued Forum Contributor
    Join Date
    09-09-2009
    Location
    Liverpool, England
    MS-Off Ver
    W: 2021 H: 365
    Posts
    940

    Re: VBA to Amend the Filter Selection on a Pivot Table Based on a Drop Down List

    Thanks for the advice dflak, much appreciated!

    Snook

+ 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: 1
    Last Post: 07-16-2015, 05:46 AM
  2. [SOLVED] Filter/Hide rows in a table based on drop-down selection?
    By kestefon in forum Excel General
    Replies: 4
    Last Post: 01-21-2015, 11:12 AM
  3. Replies: 2
    Last Post: 12-10-2014, 12:42 AM
  4. i cannot filter the values from drop down list from a pivot table report
    By mamun_08023 in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 08-21-2012, 02:50 PM
  5. Changing Pivot Report Filter based on Drop Down List Selection
    By rajuasq in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-03-2012, 11:40 AM
  6. Pivot Table selection based on Drop Down
    By kmlloyd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-27-2010, 10:06 AM
  7. Pivot Table selection based on Drop Down
    By kmlloyd in forum Excel General
    Replies: 1
    Last Post: 07-27-2010, 03:05 AM

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