Pivot Value Number Formatting

xcelljunkie

New Member
Joined
Feb 27, 2013
Messages
9
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
 

Some videos you may like

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Watch MrExcel Video

Forum statistics

Threads
1,122,669
Messages
5,597,470
Members
414,145
Latest member
lonnie451

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