Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Updating a pivottable cache in only certain sheets of a workbook

Posted on 2009-05-05
2
Medium Priority
?
443 Views
Last Modified: 2013-11-25
I have this macro right now that updates all the pivot tables in a workbook, it worked fine for the file that I was using originally because there were only about ten pivot tables to update. But now I would like to use it in a much bigger file that has a lot more pivot tables. Whenever I run the macro below on my current file I get this error message: "Excel cannot complete this task with available resources. Choose less data or close other applications." And then I get a VBA error message that says, "Run-time error '5': Invalid procedure call or argument."

So unless there's a way to make the macro below stop before my computer and Excel get overwhelmed I was just thinking about splitting the macro into three pieces. Where I would run one macro and then it would update the pivot tables in sheets: "Center", "Sony", "Howard", and "Conference". Then i would run another macro that would do it in the sheets after that, etc.

 


Public Sub UpdAllPivots()
  Dim shtThing As Worksheet
  Dim pvtThing As PivotTable
  For Each shtThing In Application.Sheets
    For Each pvtThing In shtThing.PivotTables
      pvtThing.ChangePivotCache ActiveWorkbook. _
        PivotCaches.Create(SourceType:=xlDatabase, _
        SourceData:="C:\Documents and Settings\shahryarm\Desktop\[Combined 09S 20090407v8.xlsm]Combined Grantee Main Data!R3C4:R50000C252", _
        Version:=xlPivotTableVersion12)
    Next
  Next
End Sub

Open in new window

0
Comment
Question by:hermes829
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 59

Accepted Solution

by:
Saurabh Singh Teotia earned 2000 total points
ID: 24309051
You can use the following code which will do what you are looking for..
Saurabh...

Public Sub UpdAllPivots()
  Dim shtThing As Worksheet
  Dim pvtThing As PivotTable
  For Each shtThing In Application.Sheets
  If shtThing.Name = "Center" Or shtThing.Name = "Sony" Or shtThing.Name = "Howard" Or shtThing.Name = "Conference" Then
    For Each pvtThing In shtThing.PivotTables
      pvtThing.ChangePivotCache ActiveWorkbook. _
        PivotCaches.Create(SourceType:=xlDatabase, _
        SourceData:="C:\Documents and Settings\shahryarm\Desktop\[Combined 09S 20090407v8.xlsm]Combined Grantee Main Data!R3C4:R50000C252", _
        Version:=xlPivotTableVersion12)
    Next
    End If
  Next
End Sub

Open in new window

0
 

Author Closing Comment

by:hermes829
ID: 31578220
That worked perfectly, thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question