无法设置PivotField类的Function属性

我试图在数据透视表PT2中获得“Tempo de Espera”的平均值。 但是,当我使用“.Function = xlAverage”时出现以下错误:无法设置PivotField类的Function属性。 有谁能帮我一下吗?

PT2.AddDataField PT2.PivotFields("Tempo de Espera"), "Count of Tempo de Espera", xlCount With PT2.PivotFields("Count of Tempo de Espera") .Orientation = xlDataField .Function = xlAverage 'ERROR HERE - ErrorMsg: Unable to set the Function property of the PivotField class .Caption = "Average of Tempo de Espera" .NumberFormat = "h:mm:ss" End With 

find解决scheme。 为了上面的代码工作,我必须将PivotTableVersion设置为Version15

花了整整一个下午拿到它,但终于工作。 贝娄遵循我创build数据透视表和数据透视caching时使用的代码,它设法解决这个问题:

 Set PC = ThisWorkbook.PivotCaches.Create(xlDatabase, Sheet3.Cells(1, 1).CurrentRegion, Version:=xlPivotTableVersion15) Set PT2 = Sheet4.PivotTables.Add(PivotCache:=PC, TableDestination:=Sheet4.Cells(3, c), _ TableName:="PivotTable2", DefaultVersion:=xlPivotTableVersion15)