+ Reply to Thread
Results 1 to 7 of 7

VBS Help to Auto Refresh Pivot Tables when data or specific cell values change

  1. #1
    Registered User
    Join Date
    06-20-2013
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    71

    VBS Help to Auto Refresh Pivot Tables when data or specific cell values change

    My apologies as I'm very new to VBA Code. For instance, I don't know if code should be placed under a worksheet, a workbook, or a moduel or what the difference is.

    Here's my layout:
    3 different worksheets named as follows: Summary, Data, Pivots

    "Data" has only data entries in columns A:I, there's a report label in cell A1 (centered across selection), there are Column Headers on Row 2, and data is entered in Rows 3 thru 8132. I have cells A2:I20000 setup as a defined name of "DataTable" in case that helps any for the VB code.

    "Summary" has PivotTable1 and 4 pivot table graphs (graphs are controlled by the pivot tables on "Pivots")
    "Pivots" has PivotTable2, PivotTable3, PivotTable4, PivotTable5 (this tab will be hidden from users once I'm done with this project)
    "Summary" also has 3 cells (B3, B6, and B10) and if any one of these cells is changed I need ALL 5 pivot tables auto refreshed
    Also, if any new data entries are made or any changes are made to the worksheet "Data" (or the named range "DataTable") I also want all 5 pivot tables refreshed
    - Recap: If any 1 of these 4 things change ("Data" worksheet or cells B3, B6, B10 on "Summary") then refresh all pivot tables

    How do I write VB code to handle this? And where do I place the code (worksheet, module, other)? Please be specific as I mentioned I'm a newbie and just trying to learn this stuff. Thank you for the help! Much appreciated!

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

    Re: VBS Help to Auto Refresh Pivot Tables when data or specific cell values change

    Hi kwoltman,

    Put this code behind your "Pivots" Sheet.

    Please Login or Register  to view this content.
    Every time you click on the Pivots Tab it will refresh all the pivots in the whole workbook. You don't want to refresh the pivots when you change a cell in the data tab. You wait until someone actualy looks at the pivot sheet.

    Make sense? If not then keep asking.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    06-20-2013
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    71

    Re: VBS Help to Auto Refresh Pivot Tables when data or specific cell values change

    Thank you Marvin. I tested this and it doesn't seem to work properly.

    1. I have PivotTables on 2 different worksheets. I placed your code on the "Summary" worksheet which has 1 pivot table and 4 pivot table graphs (the 4 graphs are driven by the 4 pivot tables founds on the "Pivots" worksheet).

    2. This code doesn't seem to help me with the 3 cells on the "Summary" worksheet that can be individually changed at any time and also can be changed without anything on the "Data" worksheet being changed. These 3 cells drive what the user sees in the PivotTable1 and the 4 graphs on the "Summary" worksheet.

    Additional thoughts?

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

    Re: VBS Help to Auto Refresh Pivot Tables when data or specific cell values change

    Hi,

    The code above, put behind each worksheet that has a pivot table on it should do the trick. The code says - when you activate this tab (click on the tab at the bottom) you need to refresh all tables and pivot tables in the whole workbook. If you put the code behind only one worksheet that has Pivots on it, you need to put the same code behind the other worksheet that has pivots.

  5. #5
    Registered User
    Join Date
    06-20-2013
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    71

    Re: VBS Help to Auto Refresh Pivot Tables when data or specific cell values change

    This works for when I change or add data entries to the "Data" worksheet. But it doesn't help with the 3 cells on the "Summary" tab.

    Assume that my Data worksheet is good and the user is working on the "Summary" worksheet. On the "Summary" worksheet the user can change 3 things (all 3 of these changes are independent of each other, each one DOES change data values on the table on the "Data" worksheet, but in this case the user doesn't have to move between worksheets). For instance, cell B3 has 2 choices in the drop-down: Calendar Year and Fiscal Year. When the user changes this, the data on the "Data" worksheet (column H) changes from showing 2017 (for dates between 1/1/2017-12/31/2017) or FY18 (for dates between 10/1/2017-9/30/2018). When I manually refresh my pivot table it changes what and how I see the info without ever leaving the "Summary" worksheet. But I want to automate this part too.

    So I was hoping, in addition to what you provided already, to have VB code that would also auto update the pivot tables and graphs whenever any 1 of these 3 cells (B3, B6, and B10) change when a user is on the "Summary" worksheet and may or may not leave this worksheet.

    I hope this is more clear.
    Last edited by kwoltman; 12-13-2017 at 04:15 PM.

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

    Re: VBS Help to Auto Refresh Pivot Tables when data or specific cell values change

    OK then,

    Put this code behind your Summary sheet and see if this does what you need.

    Please Login or Register  to view this content.
    The above event code says if you change anything in the B1, B6 or B10 cells it will refresh the tables and pivots in the Active workbook.

  7. #7
    Registered User
    Join Date
    06-20-2013
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    71

    Re: VBS Help to Auto Refresh Pivot Tables when data or specific cell values change

    THAT WORKS PERFECTLY! You are awesome!! Thank you very much for the help.

+ 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. [SOLVED] VBA - Auto refresh Pivot Tables
    By Wallyguy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-03-2015, 03:03 PM
  2. Auto refresh pivot tables when data changes with slight twist
    By rs1aj in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-01-2015, 11:25 AM
  3. Change data source of pivot tables and refresh them
    By yhyhyhyh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-31-2014, 04:12 AM
  4. Refresh all pivot tables upon change of data in a single cell
    By KAC1979 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 11-12-2013, 02:21 PM
  5. Refresh pivot tables on cell change
    By cmb80 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-28-2011, 07:04 AM
  6. Auto Refresh Pivot Tables
    By Marcus Hartley in forum Excel General
    Replies: 2
    Last Post: 06-03-2007, 12:49 PM
  7. [SOLVED] Pivot Tables -- Auto Refresh
    By Aastha in forum Excel General
    Replies: 1
    Last Post: 03-30-2006, 03:15 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