+ Reply to Thread
Results 1 to 2 of 2

Run macro to change pivot table row field when user selected a slicer item

  1. #1
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    104

    Run macro to change pivot table row field when user selected a slicer item

    I have a pivot table + pivot chart with 3 slicers for fiscal years, quarters and months. All slicers/slicers items are by default unselected. What I would like to do is when the user make at least one selection of a slicer item in the month slicer (for example January), it would trigger an event to run a macro to change the pivot table row field to month instead of the original row field of fiscal year + quarter. If the user makes a change in the slicer for fiscal years or quarters, nothing needs to happen, the pivot table row field stay the same (fiscal year + quarter).

    I have tested my macro initially with just a message box appearing and it is working as I want it to. My problem comes when I add the code to modify the pivot table to the change the pivot table row field to month. Because I have my trigger event on any pivot table change, when the macro make a change to the pivot table row field, it relaunch the macro (RunMacroOnSlicerChange) indefinitely and it never get to end sub and I get the following error message: Run-time error ‘-2146417949 (800010108)’: Automation Error: Object invoked has disconnected from its Clients.

    Question: Can I use another event trigger other than PivotTableUpdate? From what I found on the web, there is no such thing as a slicer selection event trigger. Or is there a way that I can temporarily unable the PivotTableUpdate so my macro can complete and then reenable it after? Thank you for your time, below is my VBA code.

    P.S. I am using Excel 2010.

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    104

    Re: Run macro to change pivot table row field when user selected a slicer item

    Found myself the solution while working on another macro Posting here if this could help someone:

    You need to add the "Application.EnableEvents = False" before calling the macro so any change to the pivot table will not trigger a PivotTableUpdate event. Once the macro finish the code put Application.EnableEvents = True at the end.

+ 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: 0
    Last Post: 08-15-2016, 02:07 PM
  2. Change Pivot Table Column field on Slicer selection (Excel 2013)
    By kevboyo in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 10-27-2014, 11:36 PM
  3. [SOLVED] Calculated Item / Field in a Pivot Table
    By DPaton in forum Excel Charting & Pivots
    Replies: 8
    Last Post: 02-17-2014, 06:32 PM
  4. [SOLVED] Macro to Update a Cell Based on Number of Items Selected in Pivot Slicer
    By MBeedle in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-15-2013, 01:47 PM
  5. Macro To Change Pivot Table Page Field
    By steve3 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-25-2007, 11:50 AM
  6. [SOLVED] Pivot Table Calculated field item
    By Tim in forum Excel General
    Replies: 1
    Last Post: 09-23-2005, 08:05 PM
  7. [SOLVED] Delete item from Pivot Table field?
    By Stephen in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 09-23-2005, 12:05 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