Solved

Updating a pivottable cache in only certain sheets of a workbook

Posted on 2009-05-05
2
413 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 500 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now