Pivot Table Automation

K

Kirk P.

I've got a procedure written to automate the creation of a pivot table. I'm
getting a "run-time error 13: type mismatch" error on the last line of the
code snippet below. The code works perfectly on one pivot table, so I copied
the code to use on another pivot table and I get this run time error. Any
ideas?

Dim WSD_s As Worksheet
Dim PTCache_s As PivotCache
Dim PT_s As PivotTable
Dim PRange_s As Range
Dim MyString_s As String

'Insert a new worksheet and name it
Set WSD_s = ActiveWorkbook.Worksheets.Add
WSD_s.Name = "PivotTable"

MyString_s =
"=OFFSET(SITE_COMPARE_DETAIL!$A$1,0,0,COUNTA(SITE_COMPARE_DETAIL!$A:$A),COUNTA(SITE_COMPARE_DETAIL!$1:$1))"
Set PRange_s = Range(MyString_s)

Set PTCache_s = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
SourceData:=PRange_s)
 
P

Patrick Molloy

is MyString_s valid?

in the immediate window you could try
Range(MyString_s ).Select
with the sheets it references as the active sheet.
 

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