Solved

Excel 2003 PivotTable.ClearTable

Posted on 2010-11-09
2
764 Views
Last Modified: 2012-05-10
My spreadsheet has a pivot table on 5 different worksheets.  Two of the pivot tables use the same datasource. The others each have their own datasource.

For the 2 tables that share the same datasource I get a warning message when I run pvtTable.ClearTable.  The message is:
The pivottable report is based on the same data as at least one other pivottable report. Clearing the pivottable report will remove the following from all the pivottable reports: grouping, calculated items, calculated fields, custom items.
See attached .jpg


Dim arrColumns
    Dim nColumns As Integer
    Dim wsReport, wsData As Worksheet
    Dim pvtTable As PivotTable
    
    Application.ScreenUpdating = False
    
    Set wsReport = Worksheets(sReportType)
    Set wsData = Worksheets(sReportType & "Query")
    theDataSource = sReportType & "Results"
   
    'Put the Column Headings of the Query Results into an array
    wsData.Select
    col = Range("A1").End(xlToRight).Select
    nColumns = Selection.Column
    ReDim arrColumns(nColumns - 1)
    For i = 0 To nColumns - 1
        arrColumns(i) = Cells(1, i + 1).Value
    Next
    
    'Clear the old pivot table and place the pivot table fields
    wsReport.Select
    Set pvtTable = wsReport.Range("A10").PivotTable
    
    pvtTable.ClearTable                 'this is the line that causes the message

Open in new window

pivottable-warning.jpg
0
Comment
Question by:CarenC
[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 81

Accepted Solution

by:
byundt earned 500 total points
ID: 34096098
Try turning Application.DisplayAlerts off (by setting it to False) prior to clearing your table.

Brad
Sub PTdeleter()
Dim pt As PivotTable
Application.DisplayAlerts = False
For Each pt In ActiveSheet.PivotTables
    pt.ClearTable
Next
Application.DisplayAlerts = True
End Sub

Open in new window

0
 

Author Closing Comment

by:CarenC
ID: 34096588
Thanks.  Didn't know that code.
0

Featured Post

Technology Partners: 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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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