Skip to content

Instantly share code, notes, and snippets.

@ateneva
Created April 16, 2017 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ateneva/16e5e3fe847787e71a4e98c68113eb0e to your computer and use it in GitHub Desktop.
Save ateneva/16e5e3fe847787e71a4e98c68113eb0e to your computer and use it in GitHub Desktop.
Change the number formatting of a PivotField
Sub ChangeNumberFormats()
Dim Wks As Worksheet
Dim PT As PivotTable
Dim PF As PivotField
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'written by Angelina Teneva, September 2016
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For Each Wks In ActiveWorkbook.Worksheets
For Each PT In Wks.PivotTables
For Each PF In PT.DataFields
If PF.SourceName Like "*Spend" Then
'comment as needed
PF.NumberFormat = "0.00" 'shows only two decimals
PF.NumberFormat = "#,###" 'shows numbers as thosands
PF.NumberFormat = "0,##" 'shows a leading zero in numbers smaller than a thousand
PF.NumberFormat = "#,##0" 'shows minus sign for negative values
PF.NumberFormat = "#,##0_);(#,##0)" 'shows negative numbers in brackets
PF.NumberFormat = "[$$-en-US]0.00" 'dollar currency symbol
PF.NumberFormat = "[$€-x-euro2] #,##0.00" 'euro currency symbol
PF.NumberFormat = "[$£-en-GB]#,##0.00" 'pound currency symbol
PF.NumberFormat = "0%; -0%;" 'hides zero values but keeps the negative ones
PF.NumberFormat = "0.0%" 'formats as %
End If
Next PF
Next PT
Next Wks
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment