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
 

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

pbornemeier

Well-known Member
Joined
May 24, 2005
Messages
3,884
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,838
Messages
5,598,383
Members
414,234
Latest member
grlevesq

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
Top