"Unable to get Pivot Tables Property of Worksheet Class "Error

C

cbalajii

I am trying to run a PIvot table macro and when I run it, I get Error
1004. However, whenever I run the same macro step by step(using F8),
it works fine . Here is the macro code..

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"'WOH details'!A:S").CreatePivotTable TableDestination:= _
"WOH!R3C1", TableName:="WOHPivot", DefaultVersion:= _
xlPivotTableVersion10
ActiveSheet.PivotTables("WOHPivot").AddFields RowFields:="Owner Name",
_
ColumnFields:="Case Calendar Age Bucket-Hrs",
PageFields:=Array( _
"Owner Work Group", "Case Priority")
ActiveSheet.PivotTables("WOHPivot").PivotFields("Case Id").Orientation
= _
xlDataField
ActiveWorkbook.ShowPivotTableFieldList = True

Any help in this regards is greatly appreciated
 
D

dq

Hi

Everything works fine when I try it. What is the exact errormessage
you get.
Usualy with this type of errors it is because your code depends on the
active sheet being 'WOH' and perhaps it isn't when you run the
macro...
Perhaps if you change it to

With ActiveWorkbook.PivotCaches.Add(xlDatabase, "'WOH details'!
A:S").CreatePivotTable("WOH!R3C1", "WOHPivot", ,
xlPivotTableVersion10)
.AddFields RowFields:="Owner Name", ColumnFields:="Case Calendar Age
Bucket-Hrs", PageFields:=Array("Owner Work Group", "Case Priority")
.PivotFields("Case Id").Orientation = xlDataField
End With
ActiveWorkbook.ShowPivotTableFieldList = True

then it does't matter wich sheet is active.

DQ
 
C

cbalajii

Thank you very much !!

I made the changes and on initial testing it seems to work...

If I have any further problems, I will respond back.

Really appreciate the excellent rapid response, :)
 

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