Thread: Pivot Problems
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Debra Dalgleish Debra Dalgleish is offline
external usenet poster
 
Posts: 2,979
Default Pivot Problems

Your SourceData range is Output!C1:C45, which would only include one
field. When it tries to add fields to the pivot table, the fields don't
exist in the source data.

Philip Wagenaar wrote:
I have created Macro's in Excel and for some reason some Pivot ones do not
work anymore. Even if I record the macro again, I still get the same error:

Run-time error '1004':
AddFields method of PivotTable class failed

The following code was produced when recording the macro:

Pivot Macro
' Macro recorded 7-9-2005 by Sigrit Janssen
'

'
Cells.Select
Range("AA1").Activate
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"Output!C1:C45").CreatePivotTable TableDestination:="", TableName:=
_
"PivotTable1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:="Actual
Start", _
ColumnFields:="Assigned To"
With ActiveSheet.PivotTables("PivotTable1").PivotFields ("Act. Dur.
Hours")
.Orientation = xlDataField
.Caption = "Sum of Act. Dur. Hours"
.Function = xlSum
End With
ActiveWorkbook.ShowPivotTableFieldList = False
Application.CommandBars("PivotTable").Visible = False
Cells.Select
Cells.EntireColumn.AutoFit
Range("B8").Select
End Sub

How can I change this code in such a way that it will work? (if I know it
for this one, I will know it for all, I think)
Why do these macro's not work anymore, even if I record the macro again?




--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html