Runtime Error 1004: Unable to get the PivotFields property of the PivotTable class

Copper Contributor

Hi there, 

 

I have this warning when i try to run a macro i0m developing.

 

The issue appears on the following row:

 

With ActiveSheet.PivotTables("TablaDinámica1").PivotFields("COMENTARIOS")

 

Here below you can find a part of the code since the pivot table was inserted:

 

Dim uFila As Long
With Sheets("Consolidado")
uFila = .Cells(.Rows.Count, 1).End(xlUp).Row
End With

Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Consolidado!R1C1:R" & uFila & " C20", Version:=8).CreatePivotTable TableDestination _
:="Hoja1!R3C1", TableName:="TablaDinámica1", DefaultVersion:=8
Sheets("Hoja1").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("TablaDinámica1")
.ColumnGrand = True
.HasAutoFormat = True
.DisplayErrorString = False
.DisplayNullString = True
.EnableDrilldown = True
.ErrorString = ""
.MergeLabels = False
.NullString = ""
.PageFieldOrder = 2
.PageFieldWrapCount = 0
.PreserveFormatting = True
.RowGrand = True
.SaveData = True
.PrintTitles = False
.RepeatItemsOnEachPrintedPage = True
.TotalsAnnotation = False
.CompactRowIndent = 1
.InGridDropZones = False
.DisplayFieldCaptions = True
.DisplayMemberPropertyTooltips = False
.DisplayContextTooltips = True
.ShowDrillIndicators = True
.PrintDrillIndicators = False
.AllowMultipleFilters = False
.SortUsingCustomLists = True
.FieldListSortAscending = False
.ShowValuesRow = False
.CalculatedMembersInFilters = False
.RowAxisLayout xlCompactRow
End With
With ActiveSheet.PivotTables("TablaDinámica1").PivotCache
.RefreshOnFileOpen = False
.MissingItemsLimit = xlMissingItemsDefault
End With
ActiveSheet.PivotTables("TablaDinámica1").RepeatAllLabels xlRepeatLabels
With ActiveSheet.PivotTables("TablaDinámica1").PivotFields("COMENTARIOS") 'ACA SE ROMPE
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("TablaDinámica1").AddDataField ActiveSheet.PivotTables( _
"TablaDinámica1").PivotFields("VALOR NETO"), "Suma de VALOR NETO", xlSum
ActiveSheet.PivotTables("TablaDinámica1").AddDataField ActiveSheet.PivotTables( _
"TablaDinámica1").PivotFields("TARIFA FINAL"), "Suma de TARIFA FINAL", xlSum
ActiveSheet.PivotTables("TablaDinámica1").AddDataField ActiveSheet.PivotTables( _
"TablaDinámica1").PivotFields("COMPARACION TARIFAS"), _
"Suma de COMPARACION TARIFAS", xlSum

 

 

Could anyone assist?

 

regards

0 Replies