+ Reply to Thread
Results 1 to 4 of 4

VBA Copy Worksheets, Changing Pivot Cache, Run Time Error 5

Hybrid View

  1. #1
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2501
    Posts
    1,438

    Re: VBA Copy Worksheets, Changing Pivot Cache, Run Time Error 5

    I think this:
    .ChangePivotCache ThisWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=NewRange)
    Needs to be:
    .ChangePivotCache wb.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=NewRange)
    ThisWorkbook is always the workbook where the code resides.
    ActiveWorkbook is the active workbook regardless of where the code resides.
    wb in this instance has been defined as ActiveWorkbook so we should use this.
    Last edited by CheeseSandwich; 03-23-2022 at 07:31 AM.

  2. #2
    Registered User
    Join Date
    03-23-2022
    Location
    Germany
    MS-Off Ver
    2019
    Posts
    2

    Re: VBA Copy Worksheets, Changing Pivot Cache, Run Time Error 5

    Quote Originally Posted by CheeseSandwich View Post
    I think this:
    .ChangePivotCache ThisWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=NewRange)
    Needs to be:
    .ChangePivotCache wb.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=NewRange)
    ThisWorkbook is always the workbook where the code resides.
    ActiveWorkbook is the active workbook regardless of where the code resides.
    wb in this instance has been defined as ActiveWorkbook so we should use this.
    Thanks

    .ChangePivotCache wb.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=NewRange)
    helped.

    I allready thoght that it might be something "small" and "very basic".

    The Structure of a code is something I might crasp and I can often tinker my way to a working code. But I really lack gramma. Time for taking some VBA training lessions :-)

    Again, thanks for the awesome and fast help

    Kind Regards

+ 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 cache error debug
    By dorabajji in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-06-2019, 11:38 AM
  2. VBA Pivot Table Cache Error
    By Fossette in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-11-2018, 06:36 AM
  3. [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
  4. HOW TO -Using same Pivot cache -different worksheets
    By pdalal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-07-2014, 03:15 PM
  5. Pivot cache error
    By Ricardo Mass in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-26-2013, 05:06 AM
  6. Changing Range on Pivot Cache
    By Wyvern in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-28-2006, 10:16 PM
  7. [SOLVED] error message with Pivot Cache
    By Wolfram Schneider in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-26-2005, 02:06 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