如何添加数据透视表的总和标准? [英] How do I add the sum criteria of pivot table?

查看:123
本文介绍了如何添加数据透视表的总和标准?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码在xlsum行显示错误,这是最后一行。应用程序定义或对象定义错误显示



我尝试过:



the code is showing error at the xlsum line which is the last line.application defined or object defined error is diplayed

What I have tried:

Sub formatPivot()
'Declaration
Dim ws As Worksheet
Dim pc As PivotCache
Dim pt As PivotTable
'Adding worksheet for the destination of the pivot table
Set ws = ActiveSheet
'Creating Pivot cache
Set pc = ActiveWorkbook.PivotCaches.Create(xlDatabase, "dashboard!R6C14:R502C18")
'Creating Pivot table
Set pt = pc.CreatePivotTable(ws.Range("T6"))
'Setting Fields
With pt
'set row field
With .PivotFields("Region Code")
.Orientation = xlRowField
.Position = 1
End With
.AddDataField .PivotFields(" Sample Compliance "), "Sum of Sample Compliance", xlSum
End With
Application.ScreenUpdating = False
End Sub

推荐答案

尝试给出支点列出一个名称并明确地引用它,例如
Try giving the pivot table a name and referring to it explicitly e.g.
With pt
    TableName:= "PivotTable1"
    'set row field
    With .PivotFields("Region Code")
        .Orientation = xlRowField
        .Position = 1
    End With
    .AddDataField ActiveSheet.PivotTables("PivotTable1").PivotFields("Sample Compliance"), "Sum of Sample Compliance", xlSum
End With



我还删除了数据域名称周围的空格


I've also removed the spaces around the datafield name


这篇关于如何添加数据透视表的总和标准?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆