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

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

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