Pivot Value Number Formatting

xcelljunkie

New Member
Joined
Feb 27, 2013
Messages
10
Hi All,

This has been a peeve of mine for years so I finally decided to do something about it. I use pivot tables all the time and have to manually change the formatting of each field because I usually have both units and revenue in the same pivot. (Each needs a different format)
I've built the following to change the formatting of the selected data field, but you have to select the data field name, and I'd like to be able to select any value in the field run it. Any ideas of how i can get the field name by selecting any value within the field?

Thanks!

Public Sub SetRevenueDataField()


Dim ptf As PivotField
Dim name As String
fldname = ActiveCell.Value
With Selection.PivotTable
.ManualUpdate = True
With .DataFields(fldname)
.NumberFormat = "$#,##0"
End With
.ManualUpdate = False
End With
End Sub

Public Sub SetUnitDataField()
Dim ptf As PivotField
Dim name As String
fldname = ActiveCell.Value
With Selection.PivotTable
.ManualUpdate = True
With .DataFields(fldname)
.NumberFormat = "#,##0"
End With
.ManualUpdate = False
End With
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,770
Messages
5,833,595
Members
430,221
Latest member
pgn29

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