提示:其它语言是由 Google 机器翻译的。 你可以访问 English 版本。
登录
x
or
x
x
马上登记
x

or

如何更改数据透视表中的多个字段设置?

在工作表中创建数据透视表时,将字段拖动到 价值 列表中 数据透视表字段列表,你可能会完全一样 计数 功能如下图所示。 但现在,你想要的 总和 的功能来取代 计数 的函数,你怎么能一次在Excel中更改多个数据透视表字段的计算?

DOC变化场设定,1

逐个手动更改数据透视表中的字段设置

使用VBA代码更改数据透视表中的多个字段设置

Office选项卡在Office中启用选项卡式编辑和浏览,使您的工作更轻松......
Kutools for Excel - 最佳办公生产力工具将解决您的大部分Excel问题
  • 重用任何东西: 将最常用或最复杂的公式,图表和其他任何内容添加到您的收藏夹中,并在将来快速重复使用它们。
  • 超过20文本功能: 从文本字符串中提取数字; 提取或删除部分文本; 将数字和货币转换为英语单词...
  • 合并工具:多个工作簿和表格合二为一; 合并多个单元格/行/列而不丢失数据; 合并重复行和总和...
  • 拆分工具:根据价值将数据拆分为多个表格; 一个工作簿到多个Excel,PDF或CSV文件; 一列到多列......
  • 粘贴跳过 隐藏/过滤行; 数和总和 按背景颜色; 创建邮件列表和 通过Cell的价值发送电子邮件...
  • 超级过滤器: 创建高级过滤方案并应用于任何工作表; 排序 按周,日,频率等; 筛选 通过大胆,公式,评论......
  • 超过300强大的功能; 适用于Office 2007-2019和365; 支持所有语言; 在公司轻松部署; 全功能60天免费试用。

箭头蓝色右泡 逐个手动更改数据透视表中的字段设置


在Excel中,您可以通过在中逐个更改函数来更改字段设置的计算 值字段设置 对话框,请这样做:

1。 在要更改数据透视表中的汇总功能的“值”区域中选择一个字段,然后单击鼠标右键进行选择 值字段设置,看截图:

DOC变化场设定,1

2。 然后在 值字段设置 对话框中,选择要在其下使用的一种计算类型 总结价值 标签,看截图:

DOC变化场设定,1

3。 然后点击 OK 关闭这个对话框,你可以看到你的Count功能已经改变为Sum功能,参见截图:

DOC变化场设定,1

4。 重复上述步骤逐个更改其他字段的计算设置。

请注意: 您也可以通过右键单击一个字段单元格并选择来更改字段设置 用数值总结数值 并从上下文菜单中选择一个您需要的计算。

DOC变化场设定,1


箭头蓝色右泡 使用VBA代码更改数据透视表中的多个字段设置

如果需要更改很多字段计算,上述方法将耗时且乏味,在此我可以向您介绍一个代码,以便同时更改多个字段设置。

1。 点击数据透视表中的任何单元格。

2。 按住 ALT + F11 键,然后打开 Microsoft Visual Basic for Applications窗口.

3。 点击 插页 > 模块,并将以下代码粘贴到 模块窗口.

VBA代码:更改数据透视表中的多个字段设置

Public Sub SetDataFieldsToSum()
'Update 20141127
Dim xPF As PivotField
Dim WorkRng As Range
Set WorkRng = Application.Selection
With WorkRng.PivotTable
   .ManualUpdate = True
   For Each xPF In .DataFields
      With xPF
         .Function = xlSum
         .NumberFormat = "#,##0"
      End With
   Next
   .ManualUpdate = False
End With
End Sub

4。 然后按 F5 键执行此代码,并且所选数据透视表中的所有字段设置已经转换为您的需求计算,请参阅屏幕截图:

DOC变化场设定,1
-1
DOC变化场设定,6

注意:在上面的代码中,您可以根据需要将Sum函数更改为任何其他计算,例如Average,Max,Min。 您只需要在这些脚本中更改总和: Public Sub SetDataFieldsToSum() .Function = xlSum 到其他功能。


Kutools for Excel - 最佳办公生产力工具提高80%的生产力

  • 重用: 快速插入 复杂的公式,图表 以及你以前用过的任何东西; 加密单元格 密码; 创建邮件列表 并发送电子邮件...
  • 超级方程式酒吧 (轻松编辑多行文字和公式); 阅读布局 (轻松读取和编辑大量单元格); 粘贴到过滤范围...
  • 合并单元格/行/列 不丢失数据; 分裂细胞含量; 组合重复的行/列...防止重复的细胞; 比较范围...
  • 选择复制或唯一 行; 选择空行 (所有细胞都是空的); 超级查找和模糊查找 在许多工作簿中; 随机选择......
  • 精确复制 多个单元格而不更改公式参考; 自动创建参考 多张表; 插入项目符号,复选框等等......
  • 提取文本,添加文本,按位置删除, 删除空间; 创建和打印分页小计; 在单元格内容和注释之间转换...
  • 超级过滤器 (将过滤方案保存并应用到其他工作表); 高级排序 按月/周/日,频率等; 特殊过滤器 用粗体,斜体......
  • 结合工作簿和工作表; 根据键列合并表; 将数据拆分为多个表格; 批量转换xls,xlsx和PDF...
  • 超过300强大的功能。 支持Office / Excel 2007-2019和365。 支持所有语言。 在您的企业或组织中轻松部署。 全功能60天免费试用。
kte tab 201905

Office选项卡为Office提供选项卡式界面,使您的工作更轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,Publisher,Access,Visio和Project。
  • 在同一窗口的新选项卡中打开并创建多个文档,而不是在新窗口中。
  • 通过50%提高您的工作效率,每天为您减少数百次鼠标点击!
官方底部
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Brian · 4 months ago
    Thank you. The code worked beautifully and saved me a lot of wasted time and energy!
  • To post as a guest, your comment is unpublished.
    Rich · 10 months ago
    I've used the VBA solution with great success in the past, but it doesn't work with the data model. Do you know if there is a solution for that?
  • To post as a guest, your comment is unpublished.
    pierrr · 10 months ago
    How about Average, Stddev, Max and Min for each field successively?
  • To post as a guest, your comment is unpublished.
    Tarryn · 1 years ago
    Brilliant!!!! Thank you so much this was amazing!!!
  • To post as a guest, your comment is unpublished.
    Harendra Singh Kuntal · 1 years ago
    SuperB... I've been frustrated with this problem
  • To post as a guest, your comment is unpublished.
    Sonia · 1 years ago
    Amazing - I am no hot shot with VBA and feel like a champion - this has been driving me crazy for a long time! Thank you
  • To post as a guest, your comment is unpublished.
    Danny · 1 years ago
    This is incredible. I've been frustrated with this problem for years, with some docs with 50+ fields. This is such a time saver!
  • To post as a guest, your comment is unpublished.
    Karishma · 2 years ago
    Change Multiple Field Settings In Pivot Table With VBA Code


    Amazing! Thank you so much. So helpful with my work.
  • To post as a guest, your comment is unpublished.
    John · 2 years ago
    Just what I was looking for !!

    Right after the .NumberFormat line, I added a rename for the column heading in the pivot, so I did not have "Sum of" in all of them.


    .Caption = " " & xPF.SourceName


    Thanks again !!
  • To post as a guest, your comment is unpublished.
    Zoltan · 2 years ago
    hi
    this is very useful thanks for that.
    im just wondering is it possible to set just a few or specific columns's value field settings?
    i mean for example i have values in the first 20 columns and i want to see the data in SUM but from 21th columns comes another type of data (for example distribution) and from that column I would like to see the data in MAX value.
    so is it possible somehow find for example the name of the header and if "distribution" is there change every "distribution" columns into MAX value.
    does it make sense?
    cheers
    Zoltan
    • To post as a guest, your comment is unpublished.
      lorbas · 1 years ago
      did you ever get a reply to this? I have the same question
  • To post as a guest, your comment is unpublished.
    Kelsey · 2 years ago
    Thanks for this! Is there any way to use StdDev instead of Sum? I was able to change your code for Average & Count, but I can't get StdDev to work. Thanks!
    • To post as a guest, your comment is unpublished.
      Gary ODriscoll · 1 months ago
      Kelsey, I just created a macro and changed one manually and then checked the macro code in VBA. To get StdDev to Work use StDev. Code becomes the following:


      Public Sub SetDataFieldsToStDev()
      'Update 20141127
      Dim xPF As PivotField
      Dim WorkRng As Range
      Set WorkRng = Application.Selection
      With WorkRng.PivotTable
      .ManualUpdate = True
      For Each xPF In .DataFields
      With xPF
      .Function = xlStDev
      .NumberFormat = "#,##0"
      End With
      Next
      .ManualUpdate = False
      End With
      End Sub
    • To post as a guest, your comment is unpublished.
      Matt · 1 years ago
      Kelsey- did you get an answer for this or figure this out? I tried to edit the code but have not been able to figure it out yet. I was not sure if there was a way to quickly change it for the different summation options. Thanks!
    • To post as a guest, your comment is unpublished.
      Michelle · 2 years ago
      Hi Kelsey - I'm wondering if you ever received an answer to this? I am trying to do the same thing. Thanks!
  • To post as a guest, your comment is unpublished.
    daniel read · 2 years ago
    This is so useful. This problem has bothered me for years and now its solved.
  • To post as a guest, your comment is unpublished.
    Jani · 2 years ago
    Hi,
    Thank you for the very good solution! Is it possible to make it automatic? So whenever I add a new Field to the values this macro should run.
    thank you in advance,
    Jani
  • To post as a guest, your comment is unpublished.
    Zwakele · 3 years ago
    Thank you for the solution.
    For reason I get an error on the .NumberFormat = "#,##0". I am changing from Sum to Average which works fine but I also want to change the NumberFormat to Number with 1 decimal.

    Thanks
  • To post as a guest, your comment is unpublished.
    Prasenjit · 4 years ago
    Hi,

    The tips and VB macros is really helpful.
    Thanks
    • To post as a guest, your comment is unpublished.
      Suhail Aboobacker · 2 years ago
      Good Day,

      Wonderful. It really helps a lot.
      Your Pivot tips are so wonderful
      I am looking for years and i got real help
      How can we add function for decimals also.
      Thanks a lot