Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在VBA中创建数据透视表:运行时错误“1004”(无法获取工作表类的数据透视表属性)_Vba_Excel_Excel 2010 - Fatal编程技术网

在VBA中创建数据透视表:运行时错误“1004”(无法获取工作表类的数据透视表属性)

在VBA中创建数据透视表:运行时错误“1004”(无法获取工作表类的数据透视表属性),vba,excel,excel-2010,Vba,Excel,Excel 2010,我正在使用Excel 2010,并使用以下VBA代码创建透视表:- Sub addFields() With ActiveSheet.PivotTables(1) With .PivotFields("Name") .Orientation = xlRowField .Position = 1 End With With .PivotFields("Location") .Orientation = xlPageField

我正在使用Excel 2010,并使用以下VBA代码创建透视表:-

Sub addFields()

  With ActiveSheet.PivotTables(1)

    With .PivotFields("Name")
      .Orientation = xlRowField
      .Position = 1
    End With

    With .PivotFields("Location")
      .Orientation = xlPageField
      .Position = 1
    End With

   .AddDataField ActiveSheet.PivotTables(1).PivotFields("Order Amount"), _
     "Sum of Amount", xlSum

  End With

End Sub
下面是Sheet1上的数据,我想在其中创建透视表

Name     Order Amount   Location
Grace    1200000        New York
Tom      2000000        New York
Madhuri  5000000        Delhi
Hari     6000000        Delhi
Raj      7000000        Delhi
Victoria 8000000        New York
但我得到了一个:

运行时错误1004:无法获取工作表类的数据透视表属性


有人可以就此提出建议吗?

错误发生在哪一行?您已经在尝试处理透视表对象,但尚未创建它。首先需要创建透视表缓存,然后才能使用上述代码。