+ Reply to Thread
Results 1 to 4 of 4

VBA - change all pivot table data sources to named range

  1. #1
    Registered User
    Join Date
    04-14-2016
    Location
    NYC
    MS-Off Ver
    2013
    Posts
    6

    VBA - change all pivot table data sources to named range

    Hi all,
    I need a macro to change all the pivot table data sources in a workbook at once. It will be changed to a named range (DataPull...) as you can see below. The code I have so far returns an error.

    Thanks!!!



    Sub ChangePTSource2()
    'Update 20141112
    Dim St As Worksheet
    Dim pt As PivotTable
    Application.ScreenUpdating = False

    For Each St In ActiveWorkbook.Worksheets
    For Each pt In St.PivotTables
    .ChangePivotCache ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="DataPullForUseFY17", Version:=xlPivotTableVersion15)
    Next
    Next

    Application.ScreenUpdating = True
    End Sub

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: VBA - change all pivot table data sources to named range

    Try to use this code:
    Please Login or Register  to view this content.
    Regards,
    Antonio

  3. #3
    Registered User
    Join Date
    04-14-2016
    Location
    NYC
    MS-Off Ver
    2013
    Posts
    6

    Re: VBA - change all pivot table data sources to named range

    Thanks, I'll try it out

  4. #4
    Registered User
    Join Date
    04-14-2016
    Location
    NYC
    MS-Off Ver
    2013
    Posts
    6

    Re: VBA - change all pivot table data sources to named range

    Quote Originally Posted by antoka05 View Post
    Try to use this code:
    Please Login or Register  to view this content.
    Regards,
    Antonio
    I get a "invalid or unqualified reference" error on the .changePivotCache line

+ 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. Button to change pivot table sources
    By skytulip in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-02-2015, 09:28 PM
  2. Pivot table with two data sources
    By Jonathan9 in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 08-08-2014, 03:10 AM
  3. [SOLVED] Assigning named Range as Pivot Table Source Data using Macro
    By Melovalicious in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-26-2012, 05:50 AM
  4. How to change the sources of all Pivot tables in a workbook to a named data range?
    By abhi.ko in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-21-2012, 01:26 PM
  5. Excel 2007 Pivot Table Data Sources
    By Legal Learning in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-06-2009, 05:30 PM
  6. Pivot table, two data sources.
    By Erasmus Bowen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-22-2005, 01:05 PM
  7. [SOLVED] Combining two data sources in a Pivot table.
    By Erasmus Bowen in forum Excel General
    Replies: 0
    Last Post: 08-19-2005, 05: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