Pivot Table problems

  • Thread starter Thread starter melvin
  • Start date Start date
M

melvin

Hi,

I have recorded a series of macros designed to create a number of
reports on excel. While the macros run, they use a Pivot Table to
create the reports. Every time the Pivot Table source data is changed
the Pivot Table changes its number (and so the VB code is invalidated),
but more confusing is that the table retains some of the data from the
previous database (the previous, deleted source data) even though I
have clicked refresh. As a result the pivot table shows data that is
not in the source data. If anyone has experienced this problem before
and/or knows how to solve it I would greatly appreciate them sharing it
with me – a bottle of 12 year old Glenfiddich to the person that solves
this!!

Many thanks for your time,

Melv
 
Your code could include the name of the PivotTable, e.g.:

'====================
Dim str As String
str = "MyPivot"
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, _
SourceData:="Database").CreatePivotTable _
TableDestination:="", TableName:=str
'====================

There's some sample code here that will remove old items from a PivotTable:

http://www.contextures.com/xlPivot04.html
 
Back
Top