+ Reply to Thread
Results 1 to 3 of 3

Consolidate Pivot Table Cache - VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    04-14-2020
    Location
    Auckland
    MS-Off Ver
    2016
    Posts
    2

    Consolidate Pivot Table Cache - VBA

    Hi all,

    First, sorry if the code isn't very simplified, still learning.

    The pivot tables 'Adam' and 'Raewyn' use exactly the same database, therefore I want to make them use the same cache (will save me 20mb in the final version).
    I have found a way to make all the pivot tables to use the same cache but not just two of them.
    Notes:
    Each pivot tables are in different sheets and the database is in another workbook.

    Thanks in advance.

    Dim Data_sht As Worksheet
    Dim Data_Blair As Worksheet
    Dim Pivot_Adam As Worksheet
    Dim Pivot_Raewyn As Worksheet
    Dim Pivot_Blair As Worksheet
    Dim StartPoint As Range
    Dim DataRange As Range
    Dim StartPointBlair As Range
    Dim DataRangeBlair As Range
    Dim PivotAdam As String
    Dim PivotRaewyn As String
    Dim PivotBlair As String
    Dim NewRange As String
    Dim BlairRange As String
    
    'Set Variables Equal to Data Sheet and Pivot Sheet
      Set Data_sht = Workbooks("Adam-Raewyn-Blair Base-en-nz").Worksheets("Adam and Raewyn")
      Set Data_Blair = Workbooks("Adam-Raewyn-Blair Base-en-nz").Worksheets("Blair")
      Set Pivot_Adam = ThisWorkbook.Worksheets("Adam")
      Set Pivot_Raewyn = ThisWorkbook.Worksheets("Raewyn")
      Set Pivot_Blair = ThisWorkbook.Worksheets("Blair")
    
    'Enter in Pivot Table Name
      PivotAdam = "PivotTable1"
      PivotRaewyn = "PivotTable2"
      PivotBlair = "PivotTable3"
    
    'Dynamically Retrieve Range Address of Data
      Set StartPoint = Data_sht.Range("A1")
      Set StartPointBlair = Data_Blair.Range("A1")
      Set DataRange = StartPoint.CurrentRegion
      Set DataRangeBlair = StartPointBlair.CurrentRegion
      
      NewRange = "'O:\Nz\Cognos Report Output\Prod\MySchool Parents\[Adam-Raewyn-Blair Base-en-nz.xlsx]Adam and Raewyn'!" & _
        DataRange.Address(ReferenceStyle:=xlR1C1)
      BlairRange = "'O:\Nz\Cognos Report Output\Prod\MySchool Parents\[Adam-Raewyn-Blair Base-en-nz.xlsx]Blair'!" & _
        DataRangeBlair.Address(ReferenceStyle:=xlR1C1)
        
    'Change Pivot Table Data Source Range Address
      Pivot_Adam.PivotTables(PivotAdam).ChangePivotCache _
        ThisWorkbook.PivotCaches.Create( _
        SourceType:=xlDatabase, _
        SourceData:=NewRange)
      Pivot_Raewyn.PivotTables(PivotRaewyn).ChangePivotCache _
        ThisWorkbook.PivotCaches.Create( _
        SourceType:=xlDatabase, _
        SourceData:=NewRange)
      Pivot_Blair.PivotTables(PivotBlair).ChangePivotCache _
        ThisWorkbook.PivotCaches.Create( _
        SourceType:=xlDatabase, _
        SourceData:=BlairRange)
    Last edited by Pepe Le Mokko; 04-14-2020 at 02:46 AM. Reason: Code tags

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2504
    Posts
    13,620

    Re: Consolidate Pivot Table Cache - VBA

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    I did it for you this time. Please read forum rules. Thanks

  3. #3
    Registered User
    Join Date
    04-14-2020
    Location
    Auckland
    MS-Off Ver
    2016
    Posts
    2

    Re: Consolidate Pivot Table Cache - VBA

    Sorry about it. Jumped into the forum and didn't follow the rules.
    Have read now and will follow it.

    Thanks for doing it for me this time
    Cheers!

+ 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. Pivot table Cache clear
    By magnus101 in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 10-25-2024, 02:06 AM
  2. [SOLVED] Macro to update pivot tables and use the SAME cache instead of repeatedly recreating cache
    By Fowzee1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-22-2015, 11:26 PM
  3. Adding a new pivot table using same pivot cache on a new worksheet
    By pdalal in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-10-2015, 05:58 AM
  4. Pivot Table Cache
    By yawnzzzz in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-06-2011, 11:49 PM
  5. Consolidate existing Pivot Tables to use one cache
    By 4am in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2011, 01:27 PM
  6. Pivot Table Cache
    By pivot in forum Excel General
    Replies: 5
    Last Post: 07-08-2009, 11:30 AM
  7. Pivot table cache
    By keithmorphett in forum Excel General
    Replies: 3
    Last Post: 11-16-2007, 06:56 AM

Tags for this Thread

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