Formatting multiple pivot table fields at the same time

stefansi

New Member
Joined
Nov 23, 2016
Messages
3
Hi,

I'm working with a large pivot table which has multiple columns for different types of costs, revenues, margins etc. and I was wondering if I can format more than one field at the same time (they're all dollar formats) to save time?

I tried to google but didn't find my answer.

Many thanks,
Stefan
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
This code should do as you asked.
Update the first Case statement to contain the names of the data fields that you DO NOT want to change formats for.

Code:
Option Explicit

Sub FormatPivotFields()

    Dim pf As PivotField
    
    For Each pf In ActiveSheet.PivotTables(1).VisibleFields

        'Debug.Print pf.Name, pf.Orientation
        If pf.Orientation = xlDataField Then
            Select Case pf.Name
            Case "NotME", "NotThisOne", "Name"
                'Won't change formats for datafields listed above
                'Add more quoted & comma separated fields as needed
            Case Else
                'Will change formats for all other data fields
                pf.NumberFormat = "$#,##0.00"
                'Debug.Print "Formatted " & pf.Name
            End Select
        End If

    Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,303
Members
449,078
Latest member
nonnakkong

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top