Program Pivot Table

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Program Pivot Table

Post by agibsonsw »

Hello. Excel 2003.

When coding to refresh a pivot table it forgets the source data - it collapses to a single row.
It also forgets the groupings I set up.
Is it possible to get around these problems? What is the instruction to redefine a PivotCaches' SourceData?

Thanks, Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
HansV
Administrator
Posts: 78631
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Program Pivot Table

Post by HansV »

Code like

ActiveSheet.PivotTables(1).PivotCache.Refresh

shouldn't "forget" the source data. What code are you using?
Best wishes,
Hans

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Program Pivot Table

Post by agibsonsw »

Hi. It's not me, and they haven't got the source code with them unfortunately.
Thanks, Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
HansV
Administrator
Posts: 78631
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Program Pivot Table

Post by HansV »

If you want to change the source data of a pivot table, you can do it like this:

ActiveSheet.PivotTables(1).SourceData = Worksheets("Sheet1").Range("A1").CurrentRegion.Address(External:=True)
Best wishes,
Hans