Pivot Table Data Field Format Macro Modification

SRMPURCHASE

Board Regular
Joined
Dec 23, 2014
Messages
148
I use this macro to change all data fields to summarize value fields by: "Sum", how would I modify it to change all data fields to "Currency" Number format?

Sub SumAllValueFields()
Dim pt As PivotTable
Dim pf As PivotField
Dim WS As Worksheet

Set WS = ActiveSheet
Set pt = WS.PivotTables(1)
Application.ScreenUpdating = False

pt.ManualUpdate = True
For Each pf In pt.DataFields
pf.Function = xlSum
Next pf
pt.ManualUpdate = False

Application.ScreenUpdating = True
Set pf = Nothing
Set pt = Nothing
Set WS = Nothing
End Sub
 

Worf

Well-known Member
Joined
Oct 30, 2011
Messages
3,756
Hi

Code:
Sub SumAllValueFields()
Dim pt As PivotTable, pf As PivotField, WS As Worksheet
Set WS = ActiveSheet
Set pt = WS.PivotTables(1)
Application.ScreenUpdating = 0
pt.ManualUpdate = True
For Each pf In pt.DataFields
    pf.Function = xlSum
    pf.NumberFormat = "$#,##0.00"
Next
pt.ManualUpdate = 0
Application.ScreenUpdating = 1
Set pf = Nothing
Set pt = Nothing
Set WS = Nothing
End Sub
 

Forum statistics

Threads
1,077,855
Messages
5,336,782
Members
399,102
Latest member
chudson1

Some videos you may like

This Week's Hot Topics

Top