Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Updating a pivottable cache in only certain sheets of a workbook

Posted on 2009-05-05
2
Medium Priority
?
446 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
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

916 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