Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Runtime Error '1004' - AddFields method of PivotTable class failed

Hi,

I can create a pivottable fine but when I record this to a macro and
try to run the macro I get an error on this line:

ActiveSheet.PivotTables("PivotTable3").AddFields
RowFields:=Array("STAGE", _
"SUB STAGE", "BUSINESS DESC", "Data"), ColumnFields:="EXPIRED"

Does anyone know what the solution to this is? (Note: I did a search
on this topic and found nothing)

Full macro code below:

Sub Create_PivotTable()
'
' Create_PivotTable Macro
' Macro recorded 21/05/2004 by MikeC
'

'
Sheets("TransferInData").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase,
SourceData:= _
"TransferInData!C1:C8").CreatePivotTable TableDestination:="",
TableName:= _
"PivotTable3", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard
TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable3").AddFields
RowFields:=Array("STAGE", _
"SUB STAGE", "BUSINESS DESC", "Data"), ColumnFields:="EXPIRED"
With ActiveSheet.PivotTables("PivotTable3").PivotFields ("BUSINESS
DESC")
.Orientation = xlDataField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable3").PivotFields ("PROCESSED")
.Orientation = xlDataField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable3").PivotFields ("BUSINESS
DESC"). _
Orientation = xlDataField
ActiveWorkbook.ShowPivotTableFieldList = True
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveWindow.SmallScroll Down:=12
End Sub

Regards,

MikeC
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default I've found a workaround

The workaround for recording a macro that creates a pivottable is
simple enough:

- Create a spreasheet with a pivottable pointing to the dataset
- Record a macro that will refresh the pivottable

I think that Excel has problems with the naming of the pivottable when
it tries to create it from scratch ie each time you run the macro,
Excel will name it PivotTable1, then PivotTable2,.. and so on.

I'll keep an eye out for any solutions to my problem still (not just
workarounds).

Thanks

(MikeC) wrote in message . com...
Hi,

I can create a pivottable fine but when I record this to a macro and
try to run the macro I get an error on this line:

ActiveSheet.PivotTables("PivotTable3").AddFields
RowFields:=Array("STAGE", _
"SUB STAGE", "BUSINESS DESC", "Data"), ColumnFields:="EXPIRED"

Does anyone know what the solution to this is? (Note: I did a search
on this topic and found nothing)

Full macro code below:

Sub Create_PivotTable()
'
' Create_PivotTable Macro
' Macro recorded 21/05/2004 by MikeC
'

'
Sheets("TransferInData").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase,
SourceData:= _
"TransferInData!C1:C8").CreatePivotTable TableDestination:="",
TableName:= _
"PivotTable3", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard
TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable3").AddFields
RowFields:=Array("STAGE", _
"SUB STAGE", "BUSINESS DESC", "Data"), ColumnFields:="EXPIRED"
With ActiveSheet.PivotTables("PivotTable3").PivotFields ("BUSINESS
DESC")
.Orientation = xlDataField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable3").PivotFields ("PROCESSED")
.Orientation = xlDataField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable3").PivotFields ("BUSINESS
DESC"). _
Orientation = xlDataField
ActiveWorkbook.ShowPivotTableFieldList = True
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveWindow.SmallScroll Down:=12
End Sub

Regards,

MikeC

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Runtime 1004 error -- insert method of range class failed. tish Excel Discussion (Misc queries) 1 June 1st 07 04:04 PM
RUNTIME ERROR '1004' --- Select method of worksheet class failed jawee Excel Programming 2 April 30th 04 06:47 AM
runtime error '1004' delete Method of Range Class Failed Tom Kennedy Excel Programming 0 April 14th 04 08:08 PM
runtime error '1004' delete Method of Range Class Failed Tom Ogilvy Excel Programming 0 April 1st 04 04:09 AM
excel97: runtime error 1004 select method of range class failed JMCN Excel Programming 4 December 25th 03 05:32 AM


All times are GMT +1. The time now is 11:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"