Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to change multiple field settings in pivot table?

When you create a pivot table in a worksheet, after dragging the fields to the Values list in the PivotTable Field List, you may get all the same Count function as following screenshot shown. But now, you want the Sum of function to replace the Count of function at once, how could you change the calculation of multiple pivot table fields at once in Excel?

doc-change-field-setting-1

Change the field settings in pivot table manually one by one

Change multiple field settings in pivot table with VBA code


arrow blue right bubble Change the field settings in pivot table manually one by one


In Excel, you can change the calculation of the field settings by changing the function one by one in the Value Field Settings dialog, please do as this:

1. Select a field in the Values area for which you want to change the summary function in the pivot table, and right click to choose Value Field Settings, see screenshot:

doc-change-field-setting-1

2. Then in the Value Field Settings dialog box, select one type of calculate which you want to use under the Summarize Value By tab, see screenshot:

doc-change-field-setting-1

3. And then click OK to close this dialog, and you can see your Count function has been changed to Sum function, see screenshot:

doc-change-field-setting-1

4. Repeat the above steps to change other fields’ calculation settings one by one.

Note: You can also change the field settings by right click one field cell and choose Summarize Values by and select one calculation you need from context menus.

doc-change-field-setting-1


arrow blue right bubble Change multiple field settings in pivot table with VBA code

The above method will be time consuming and tedious if there are lots of field calculations needed to be changed, here, I can introduce you a code to change multiple filed settings at the same time.

1. Click any cell in your pivot table.

2. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

3. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Change multiple field settings in pivot table

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. Then press F5 key to execute this code, and all the field settings in your selected pivot table have been converted to your need calculation at once, see screenshots:

doc-change-field-setting-1
-1
doc-change-field-setting-6

Note: In the above code, you can change the Sum function to any other calculations, such as Average, Max, Min as you want. You just need to change the Sum in these scripts: Public Sub SetDataFieldsToSum() and .Function = xlSum to other functions.


Recommended Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 71%, and Help You To Stand Out From Crowd!

Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 82% Excel problems.

  •  Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
  •  Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  •  Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
  •  Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
  •  No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
  •  Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
  •  60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  •  Change the way you work now, and give you a better life immediately!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
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 · 3 days 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 · 6 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 · 6 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