+ Reply to Thread
Results 1 to 11 of 11

How to automatically refresh a pivot table when data changes?

  1. #1
    Registered User
    Join Date
    07-31-2015
    Location
    Washington
    MS-Off Ver
    Office 365
    Posts
    9

    How to automatically refresh a pivot table when data changes?

    I have a worksheet with a pivot table on Sheet1 and my data in Sheet2.

    I need the pivot table to refresh if anything in D2 through D25 in Sheet2 changes. (or just column D altogether)

    For the life of me I can't find a straight solution to this anywhere and it seems so simple, yet I seem to get some sort of error every time. Do I need to have them in the same worksheet?


    Any help would be greatly appreciated. Thank you!

  2. #2
    Valued Forum Contributor
    Join Date
    02-07-2013
    Location
    Philippines
    MS-Off Ver
    Excel Online; 365
    Posts
    633

    Re: How to automatically refresh a pivot table when data changes?

    Try this with a Worksheet Activate change event:

    Sheet1.PivotTables("name of pivot").RefreshTable
    If I've helped U pls click on d *Add Reputation

  3. #3
    Registered User
    Join Date
    07-31-2015
    Location
    Washington
    MS-Off Ver
    Office 365
    Posts
    9

    Re: How to automatically refresh a pivot table when data changes?

    How completely wrong is what I typed in?

    Private Sub Worksheet_Change(ByVal Target As Range)
    Sheet1.PivotTables("Chart 1").RefreshTable
    End Sub


    I received this error:

    run-time error '10004':

    Method 'PivotTables' of object '_Worksheet' failed

  4. #4
    Valued Forum Contributor
    Join Date
    02-07-2013
    Location
    Philippines
    MS-Off Ver
    Excel Online; 365
    Posts
    633

    Re: How to automatically refresh a pivot table when data changes?

    have you tried putting it on WOrksheet Activate?

    or you can add the On Error Resume Next statement on the first line.

  5. #5
    Registered User
    Join Date
    07-31-2015
    Location
    Washington
    MS-Off Ver
    Office 365
    Posts
    9

    Re: How to automatically refresh a pivot table when data changes?

    The data is connected to an access database on SharePoint. The worksheet isn't actually opened or anything, so I don't know if activate would work? I need the pivot table to refresh because it is being displayed on the SharePoint page.

    Is this what you mean?

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    'ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
    Me.PivotTables(1).RefreshTable
    End Sub


    Nothing happens now.

  6. #6
    Valued Forum Contributor
    Join Date
    02-07-2013
    Location
    Philippines
    MS-Off Ver
    Excel Online; 365
    Posts
    633

    Re: How to automatically refresh a pivot table when data changes?

    then maybe you can use a Workbook change event instead of a worksheet change event

    Workbook_SheetChange or Open

  7. #7
    Registered User
    Join Date
    07-31-2015
    Location
    Washington
    MS-Off Ver
    Office 365
    Posts
    9

    Re: How to automatically refresh a pivot table when data changes?

    Do I have to put something in ByVal Target As Range?

  8. #8
    Valued Forum Contributor
    Join Date
    02-07-2013
    Location
    Philippines
    MS-Off Ver
    Excel Online; 365
    Posts
    633

    Re: How to automatically refresh a pivot table when data changes?

    No. just paste your code in the Workbook Sheet Change event:

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

    Sheet1.PivotTables("Chart 1").RefreshTable

    End Sub

  9. #9
    Registered User
    Join Date
    07-31-2015
    Location
    Washington
    MS-Off Ver
    Office 365
    Posts
    9

    Re: How to automatically refresh a pivot table when data changes?

    I don't know...
    Last edited by JohnJK04; 07-31-2015 at 08:48 PM.

  10. #10
    Registered User
    Join Date
    07-31-2015
    Location
    Washington
    MS-Off Ver
    Office 365
    Posts
    9

    Re: How to automatically refresh a pivot table when data changes?

    Got it. Thanks for your help!

    Private Sub Worksheet_Change(ByVal Target As Range)
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.PivotLayout.PivotTable.PivotCache.Refresh
    End Sub

  11. #11
    Valued Forum Contributor
    Join Date
    02-07-2013
    Location
    Philippines
    MS-Off Ver
    Excel Online; 365
    Posts
    633

    Re: How to automatically refresh a pivot table when data changes?

    right click Sheet1 tab then View Code then on Project Explorer choose ThisWorkbook

    then paste this code:

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

    Sheet1.PivotTables("Chart 1").RefreshTable

    End Sub

+ 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] VB Code to Refresh Pivot Table Automatically every 5 mins - For Dashboard
    By MarkyP18 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-06-2015, 04:38 PM
  2. Replies: 0
    Last Post: 08-14-2013, 06:31 AM
  3. [SOLVED] Pivot table does not refresh automatically.
    By Whitenoise1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-28-2012, 11:38 AM
  4. Automatically refresh pivot tables after data entry
    By Hodgepodge in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-14-2011, 06:27 AM
  5. Automatically Refresh Pivot Table with new date
    By meyero90 in forum Excel General
    Replies: 9
    Last Post: 08-04-2010, 08:42 AM
  6. Pivot table refresh automatically???/
    By devesh.agrawal in forum Excel General
    Replies: 1
    Last Post: 09-23-2008, 08:34 AM
  7. Refresh Pivot Table Automatically
    By anandmr65 in forum Excel General
    Replies: 1
    Last Post: 07-11-2006, 08:04 AM
  8. Excel 2002 Refresh Pivot Table Automatically
    By ~Dave~ in forum Excel General
    Replies: 2
    Last Post: 07-28-2005, 09: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