【发布时间】:2019-05-24 08:02:22
【问题描述】:
我使用数据透视表进行计算。
我想做一个通用的数据透视表,并且可以一直工作,我有同样的计算要做。
我试过了,但它不起作用,计算总是在数据透视表中阻塞。
Sheets.Add.Name = "tdc_flux"
Sheets("flux phf a+1").Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"flux phf a+1!R1C1:R1048576C16", Version:=6).CreatePivotTable _
TableDestination:="tdc_flux!R3C1", TableName:="Tableau croisé dynamique3", _
DefaultVersion:=6
Sheets("tdc_flux").Select
Cells(1, 1).Select
With ActiveSheet.PivotTables("Tableau croisé dynamique3")
.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("Tableau croisé dynamique3").PivotCache
.RefreshOnFileOpen = False
.MissingItemsLimit = xlMissingItemsDefault
End With
ActiveSheet.PivotTables("Tableau croisé dynamique3").RepeatAllLabels _
xlRepeatLabels
With ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields( _
"Concatner (ref +div)")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields( _
"Type de flux")
.Orientation = xlColumnField
.Position = 1
End With
ActiveSheet.PivotTables("Tableau croisé dynamique3").AddDataField ActiveSheet. _
PivotTables("Tableau croisé dynamique3").PivotFields(" En DICtrPr"), _
"Somme de En DICtrPr", xlSum
ActiveSheet.PivotTables("Tableau croisé dynamique3").AddDataField ActiveSheet. _
PivotTables("Tableau croisé dynamique3").PivotFields(" En DICtrPr"), _
"Somme de En DICtrPr", xlSum
这是它阻塞的部分。
“Somme”是英文的 sum,“Tableau croisé dynamque”是数据透视表的名称。
【问题讨论】:
-
块是什么意思?有错误信息吗?程序运行似乎只是冻结了吗?
-
@QHarr 是的,程序运行良好,直到我输入的段落出现错误消息。当我打开创建的工作表时,只有列和行的名称,但没有值。
-
错误信息是什么?
-
@QHarr 执行错误 1004 无法读取 PivotTable 类的 PivotField 属性。
标签: excel vba pivot-table