How to add multiple fields into pivot table?
When we create a pivot table, we need to drag the fields into the Row Labels or Values manually one by one. If we have a long list of fields, we can add a few row labels quickly, but the remaining fields should be added to the Value area. Are there any quick methods for us to add all the other fields into the Value area with one click in the pivot table?
Recommended Productivity Tools for Excel
Office Tab: Bring powerful tabs to Office (include Excel), just like Chrome, Safari, Firefox and Internet Explorer. Save you half the time, and reduce thousands of mouse clicks for you. 30-day Unlimited Free Trial
Kutools for Excel: Save 71% of your time and solve 82% Excel problems for you. 300+ advanced tools designed for 1500+ work scenario, make Excel much easy and increase productivity immediately.60-day Unlimited Free Trial
Unfortunately, there is no checkbox for us to quickly check all the fields in the Pivot Table Field List with one click, but, with the following VBA code it can help you to add the remaining fields to the Values area at once. Please do as follows:
1. After creating the pivot table, firstly, you should add the row label fields as your need, and leaving the value fields in the Choose fields to add to report list, see screenshot:< /p>
2. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
3. Click Insert > Module, and paste the following code in the Module Window.
VBA code: Add multiple fields into Value area of pivot tables in active worksheet
Sub AddAllFieldsValues() 'Update 20141112 Dim pt As PivotTable Dim I As Long For Each pt In ActiveSheet.PivotTables For I = 1 To pt.PivotFields.Count With pt.PivotFields(I) If .Orientation = 0 Then .Orientation = xlDataField End With Next Next End Sub
4. Then press F5 key to run this code, all the remaining fields have been added to the Values area at same time, see screenshot:
Note: This VBA code is applied to all pivot tables of active worksheet.
Recommended Productivity Tools
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
To post as a guest, your comment is unpublished.· 10 months agoWorks like a charm. Thanks
To post as a guest, your comment is unpublished.· 1 years agoHi.
It gives me a compile error when I click on Run
To post as a guest, your comment is unpublished.· 1 years agoDoes "xlDataField" not work with PowerPivot? I've got the code below, which is used to add all measures to the pivot table. It works with "xlColumnField" and "xlRowField". Any ideas how to make this work?
Dim pt As PivotTable
Dim iCol As Long
Dim iColEnd As Long
Set pt = ActiveSheet.PivotTables(1)
iCol = 1
iColEnd = .CubeFields.Count
For iCol = 1 To iColEnd
If .Orientation = xlHidden Then
.Orientation = xlDataField
To post as a guest, your comment is unpublished.· 1 years agoThis is great! Thanks.
To post as a guest, your comment is unpublished.· 1 years agoIts takiung value as count. how can i convert all count as Sum
To post as a guest, your comment is unpublished.· 1 years agoYou can click on your field (in the area where you drag your fields into : column labels, row labels etc.) then click on "Value field setting" then you will get a dropdown list from where you can chose "Sum" !
To post as a guest, your comment is unpublished.· 1 years agoVBA code: Change multiple field settings in pivot table