简体   繁体   English

关闭Excel数据透视表子总计VB.NET

[英]Turning off Excel Pivot Table Sub Totals VB.NET

I am creating pivot tables in VB.NET and have run into a problem I did not think would be as difficult as it is turning out. 我正在VB.NET中创建数据透视表,并遇到了一个问题,我认为这个问题并不像它的结果那么困难。 When I create a pivot table it adds in subtotals for each row and I do not want that. 当我创建一个数据透视表时,它会为每一行添加小计,我不希望这样。 In excel you just drag down the subtotals option and tell it to not display subtotals. 在excel中,您只需拖动小计选项并告诉它不显示小计。 I looked into the VBA for it and it is several lines long of this format: 我查看了它的VBA,这个格式有几行:

     ActiveSheet.PivotTables("Main Highway Pivot").PivotFields("Division"). _
    Subtotals = Array(False, False, False, False, False, False, False, False, False, False, _
    False, False)

This is a surprising amount of code, but that is fine, so I have been trying something similar with my pivot table in VB.NET 这是一个令人惊讶的代码量,但这很好,所以我一直在尝试类似于VB.NET中的数据透视表

With ptTable
.ManualUpdate = True
.PivotFields("Division").orientation = Excel.XlPivotFieldOrientation.xlRowField
.PivotFields("Net Sales Amt").orientation = Excel.XlPivotFieldOrientation.xlDataField
.PivotFields("Division").Subtotals = false
.ColumnGrand = False
.RowGrand = True
.ManualUpdate = False
End With

I have tried several different variations of the 我尝试了几种不同的变体

 .PivotFields("Division").Subtotals = false

line, but have had little luck. 线,但运气不好。 Is this the right code and I am specifying the false part wrong? 这是正确的代码,我指定错误的部分错了吗? Why is there no 为什么没有

.subtotal = false

to make this easier? 使这更容易?

In any case, it seemed like something simple to me, but after a good bit of digging I am not sure how to fix it, so any help would be appreciated. 在任何情况下,对我来说似乎都很简单,但经过一段时间的挖掘后我不知道如何修复它,所以任何帮助都会受到赞赏。

Thank you as always SO 谢谢你一如既往

Here's a snippet of VBA (from http://www.pcreview.co.uk/forums/hide-subtotals-rowfields-pivot-table-t974940.html ) which might help: 这是VBA的片段(来自http://www.pcreview.co.uk/forums/hide-subtotals-rowfields-pivot-table-t974940.html ),这可能会有所帮助:

'=========================
Sub NoSubtotals()
'turns off subtotals in pivot table
'.PivotFields could be changed to
'.RowFields or .ColumnFields
Dim pt As PivotTable
Dim pf As PivotField
On Error Resume Next
For Each pt In ActiveSheet.PivotTables
For Each pf In pt.PivotFields
'First, set index 1 (Automatic) to True,
'so all other values are set to False
pf.Subtotals(1) = True
pf.Subtotals(1) = False
Next pf
Next pt
End Sub
'========================

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM