首页 > 解决方案 > 尝试创建数据透视表时出错

问题描述

我一直在尝试运行以下宏来创建一个超出另一张数据表范围的数据透视表,但我似乎无法使其工作。

Sub topc()

Application.ScreenUpdating = False

Application.DisplayAlerts = False
Worksheets("TOP C").Delete
Sheets.Add Before:=ActiveSheet
ActiveSheet.Name = "TOP C"
Application.DisplayAlerts = True



ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Complaints!R1C1:R3000C32", Version:=6).CreatePivotTable _
        TableDestination:="TOP C!R1C1", TableName:="PivotTable1", _
        DefaultVersion:=6


      ActiveSheet.PivotTables("PivotTable1").RepeatAllLabels xlRepeatLabels
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Recurrence")
        .Orientation = xlColumnField
        .Position = 1
    End With

      ActiveSheet.PivotTables("PivotTable1").RepeatAllLabels xlRepeatLabels
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Subtype Name")
        .Orientation = xlRowField
        .Position = 1
    End With

      With ActiveSheet.PivotTables("PivotTable1").PivotFields("Type Inquiry")
        .Orientation = xlPageField
        .Position = 1
    End With

        ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
        "PivotTable1").PivotFields("Value"), "Sum of Value", xlSum


End Sub

我在这个区域不断收到错误“无效的过程或参数”:

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
       "Complaints!R1C1:R3000C32", Version:=6).CreatePivotTable _
       TableDestination:="TOP C!R1C1", TableName:="PivotTable1", _
       DefaultVersion:=6

并不断告诉我 xlDatabase = 1, idk 如果那是问题所在。请帮忙!!

标签: excelvbapivot-table

解决方案


推荐阅读