I am having a similar issue. I have a file with four total worksheets, three of them being pivot tables that are created from the data in worksheet 4. I am looking for a way to refresh the tables every time I change the data. I tried recording my own macro, but receive the following error:
1004
"Unable to get the PivotField property of the PivotTable Class."
The code that recorded is below. I am much more familiar with coding in
Access, so don't even know where to start here.
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"tempPO_ExpSumm!C1:C4").CreatePivotTable TableDestination:="",
TableName:= _
"PivotTable4", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable4").PivotFields("Expeditor")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable4").PivotFields("LS_Date")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable4").PivotFields("PO_Type")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable4").AddDataField
ActiveSheet.PivotTables( _
"PivotTable4").PivotFields("PO_Count"), "Count of PO_Count", xlCount