“无法获取数据透视表类的数据透视属性” runtierror

时间:2019-01-04 08:48:40

标签: excel vba excel-vba pivot-table

在运行下面的代码时,出现运行时错误“无法获取数据透视表类的ivotFields属性”。每种情况(1,2,3,4)都会引发错误。我不明白代码有什么问题。有人可以帮忙吗?

 Sub KPIselect()  
 Dim Pvt As PivotTable
 Dim Pf As PivotField
 Dim Sh As Worksheet
 Set Sh = Workbooks("CIFM doc.xlsm").Worksheets("KPI viewer")
 Set Pvt = Sh.PivotTables("PivotTable1")

 If Sh.Range("Selection") = Sh.Range("Calc.Type") Then
   Exit Sub
 Else
   For Each Pf In Pvt.DataFields

    Select Case Range("Selection.number")
    Case 1
    Pvt.AddDataField Pvt.PivotFields("Project Sales (sqft)"),"Sum of Project Sales (sqft)"
    Case 2
    Pvt.AddDataField Pvt.PivotFields("Launch Area (Sqft)"), "Sum of Launch Area (Sqft)"
    Case 3
    Pvt.AddDataField Pvt.PivotFields("Sustenance Area (Sqft)"),"Sum of Sustenance Area (Sqft)"
    Case 4
    Pvt.AddDataField Pvt.PivotFields("CoC"), "Sum of CoC", xlSum

   End Select
   Next Pf
   End If

   End Sub

0 个答案:

没有答案