Results 1 to 10 of 10

Updating data source and refreshing all pivot tables through VBA.

Threaded View

  1. #1
    Registered User
    Join Date
    09-16-2010
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    68

    Updating data source and refreshing all pivot tables through VBA.

    Hi all,

    I have a spreadsheet containing several pivot tables, all based on the same data source. From time to time, the data source is updated is additional rows (column A never contains any empty cells), therefore I created the following macro to update the data source of all pivot tables as well as refreshing those:

    Sub Refresh_All_Pivot_Tables()
    
    Application.ScreenUpdating = False
    
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim pt As PivotTable
    
    Set wb = ActiveWorkbook
    SourceName = Worksheets("MasterSheet").Range("A1:AX1").End(xlDown)
    
      For Each ws In wb.Worksheets
        For Each pt In ws.PivotTables
          pt.ChangePivotCache _
            wb.PivotCaches.Create(SourceType:=xlDatabase, _
                  SourceData:=SourceName)
        Next pt
      Next ws
    
    ActiveWorkbook.RefreshAll
    
    Application.ScreenUpdating = True
    
    End Sub
    However it seems to fail when applying the SourceName variable. I am not sure where the issue could lie, I used F8 and watched the variables but the macro seems to do something completely different than what at I am expecting (i.e. simply update the source of each pivot tables using range A1:AX1 to the bottom of the 'MasterSheet' worksheet).

    Any help would be appreciated. Thanks.

    PS: I also used

    PT.SourceData = SourceName
    instead of

    wb.PivotCaches.Create(SourceType:=xlDatabase, _
    SourceData:=SourceName)
    but this did not help.
    Last edited by Folshot; 11-24-2013 at 12:30 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Change Pivot Source Data in multiple pivot tables
    By jacol in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 05-20-2014, 06:18 AM
  2. Replies: 3
    Last Post: 02-27-2012, 08:03 PM
  3. Pivot Tables and VBA: Changing Contents in Data Area and updating the Data Source
    By kyrgyzstanart in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-22-2011, 11:11 AM
  4. [SOLVED] updating pivot tables using dynamic data source
    By dab4211 in forum Excel General
    Replies: 3
    Last Post: 07-24-2006, 04:45 PM
  5. Updating source data while in Pivot Table
    By Carim in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-27-2005, 10:06 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