Skip to main content

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.

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

Description


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Comments (29)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Brilliant, thanks, this worked perfectly and save much time
This comment was minimized by the moderator on the site
Muchas gracias por el aporte
This comment was minimized by the moderator on the site
Hi!

I'm wondering how to use the code for Count Numbers instead of count, I've tried changing the code to Count Numbers and CountNumbers but netiher works..

Help is appreciated :)
This comment was minimized by the moderator on the site
Hello, Sara,
Sorry for that your Count Numbers field can't be changed in the code, so, you need to change the field one by one with the first method in this article.
Thank you!
This comment was minimized by the moderator on the site
Thank you so much, this VBA code works amazing. 
This comment was minimized by the moderator on the site
I got the error" Unable to get the PivotTable property of the range class". Do you know hoe can I fix this?
This comment was minimized by the moderator on the site
I got this error, "Unable to get the Pivot Table property of the Range class". Do you know how I can fix this?
This comment was minimized by the moderator on the site
Thank you so much!!! That is sooo helpful and brilliant! Saved me soooo much time
This comment was minimized by the moderator on the site
Thank you so much for the VBA code, I LOVE it!
This comment was minimized by the moderator on the site
Thank you. The code worked beautifully and saved me a lot of wasted time and energy!
This comment was minimized by the moderator on the site
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?
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations