交换枢轴 table 列 headers 的位置

Swap positions of pivot table column headers

我想交换枢轴 table 列的位置 headers

根据截图:

第 header 列属于“报价类型”列。

我希望第 header 列 TYPE 1 位于第 header 列 TYPE 2 的左侧,后者又位于第 header 列 TYPE 3 的左侧。

忽略空格。

非常感谢!

如果您只想执行此操作一次,您可以手动拖动 headers,但使用 VBA,您可以执行如下操作:

    With Sheets("YourSheet").PivotTables("YourPivotTable").PivotFields("Quote Type")
        .PivotItems("TYPE 1").Position = 1
        .PivotItems("TYPE 2").Position = 2
        .PivotItems("TYPE 3").Position = 3
    End With

不要忘记将 YourSheet 替换为具有数据透视表的工作表名称 table,并将 YourPivotTable 替换为数据透视表的名称 table!

注意:如果其中一种类型不在枢轴 table 中,这将产生错误。如果您愿意,可以在它之前添加 On Error Resume Next 或为其创建自定义错误处理程序。如果这是您需要的,请告诉我。