Pivot Table Creation

R

Rob

I'm having trouble programatically creating a pivot table. If I step through
the code below it works, but if I run it, it falls over on the Set PT line.
Can anyone see a problem with my code?
Thanks
Rob

Sub MakePivot(ReportName As String, DataAddress As String, ReportAddress As
Range)

Dim PTcache As PivotCache
Dim PT

Set PTcache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
SourceData:=DataAddress)
Set PT = PTcache.CreatePivotTable(TableDestination:=ReportAddress,
TableName:=ReportName)
 
C

colofnature

I usually find it easiest to cheat and record the creation of a pivot
table, then tweak the pivottablewizard code... it's inelegant, but it
saves a lot of time!

Col
 
R

Rob

I found the solution. If anyone's interested then here's what was happening:

The DataAddress parameter being passed to the function did not include the
sheet name. (ie. it was something like "A1:H50"). When stepping through,
excel had time to resolve this address as referring to the active sheet, but
when Running, it did not.

Regards
Rob
 

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