用于创建数据透视表的VBA代码

时间:2017-09-27 13:11:40

标签: excel vba excel-vba pivot-table

我创建了一个构建数据透视表的宏。它运行良好,但我想忽略提供的屏幕截图中的圆圈内容..我不想在枢轴内部有总数。只有在总计的底部!我提供我的代码和截图。此外,是否可以用“FDD”替换B列中的“行标签”文本?

enter image description here

enter image description here

+--------------------+----------------+----------------+-----------+---+
|         patient_gid|interaction_desc|interaction_date|rx_end_date|rnk|
+--------------------+----------------+----------------+-----------+---+
|00000000000072128380|           prod1|      2009-02-23| 2009-05-22|  1|
|00000000000072128380|           prod1|      2010-04-05| 2009-05-22|  2|
|00000000000072128380|           prod1|      2009-03-23| 2009-05-22|  3|
|00000000000072128380|           prod1|      2009-04-20| 2009-05-22|  4|
|00000000000072128380|           prod1|      2009-05-16| 2009-05-22|  5|
|00000000000072128380|           prod1|      2009-06-17| 2009-05-22|  6|
|00000000000072128380|           prod1|      2009-07-15| 2009-05-22|  7|
|00000000000072128380|           prod1|      2009-08-12| 2009-05-22|  8|
|00000000000072128380|           prod1|      2009-09-05| 2009-05-22|  9|
|00000000000072128380|           prod1|      2009-10-06| 2009-05-22| 10|
|00000000000072128380|           prod2|      2009-10-28| 2009-05-22|  1|
|00000000000072128380|           prod2|      2009-12-02| 2009-05-22|  2|
|00000000000072128380|           prod2|      2010-05-10| 2009-05-22|  3|
|00000000000072128380|           prod2|      2008-05-22| 2009-05-22|  4|
|00000000000072128380|           prod2|      2010-07-06| 2009-05-22|  5|
|00000000000072128380|           prod2|      2010-08-03| 2009-05-22|  6|
|00000000000072128380|           prod2|      2010-09-23| 2009-05-22|  7|
|00000000000072128380|           prod2|      2010-10-20| 2009-05-22|  8|
|00000000000072128380|           prod2|      2010-01-29| 2009-05-22|  9|
|00000000000072128380|           prod2|      2008-05-22| 2009-05-22| 10|
+--------------------+----------------+----------------+-----------+---+

1 个答案:

答案 0 :(得分:4)

您可以切换小计:

With PTable.PivotFields("Commodity Code")
.Orientation = xlRowField
.Position = 1
.Name = "Commodity Code"
.Subtotals(1) = True
.Subtotals(1) = False
End With

更改标题,将表格布局更改为表格

PTable.LayoutRowDefault = xlTabularRow
在添加字段之前

。顺便说一句,您应该在代码的其余部分使用PTable而不是ActiveSheet.PivotTables("PivotTable")