Changing PivotTable source

A

atakacs

Folks

I'd like to programmatically change the source data of an existing
PivotTable...

Tried


Code:
--------------------
Activesheet.PivotTables("PivotTable1").SourceData = "PivotTable_Data"
--------------------


Where "PivotTable1" is an existing pivot table and "PivotTable_Data" a
valid named range... but this doesn't work...

Any suggestion ?

Regards

--alex
 
T

Tom Ogilvy

Why not set the source to a named range originally, then redefine the
definition of the named range.
 
N

Ngalula Kachika Michel

Try this:

Private Sub Worksheet_Activate()
Worksheets("Base").Range("cellule").CurrentRegion.Name
= "cellule"
ActiveSheet.PivotTableWizard SourceType:=xlDatabase,
SourceData:="cellule"
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top