#1   Report Post  
 
Posts: n/a
Default Macro Help

All,

This macro was supplied by a member of the group: Debra Dalgleish

Very helpfull

Sub ResetCaptions()
'retrieve original field names
'if captions have been typed into pt
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pt = ActiveSheet.PivotTables(1)
For Each pf In pt.VisibleFields
For Each pi In pf.PivotItems
pi.Caption = pi.SourceName
Next pi
Next pf
pt.RefreshTable
End Sub

I need to do this for only one pivotitem for all pivot tables on the
active sheet. I dont sem to be able to get this to work though I am
sure it is simple.

Can someone help?

Doug

  #2   Report Post  
Debra Dalgleish
 
Posts: n/a
Default

You could use code similar to the following:

'=====================Sub ResetCaptionsOneItem()
'retrieve original field names
'if captions have been typed into pt
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Dim strField As String
Dim strItem As String
strField = "Region"
strItem = "East"

For Each pt In ActiveSheet.PivotTables
Set pf = pt.PivotFields(strField)
For Each pi In pf.PivotItems
If pi.SourceName = strItem Then
pi.Caption = pi.SourceName
Exit For
End If
Next pi
pt.RefreshTable
Next pt
End Sub
'=================

wrote:
All,

This macro was supplied by a member of the group: Debra Dalgleish

Very helpfull

Sub ResetCaptions()
'retrieve original field names
'if captions have been typed into pt
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pt = ActiveSheet.PivotTables(1)
For Each pf In pt.VisibleFields
For Each pi In pf.PivotItems
pi.Caption = pi.SourceName
Next pi
Next pf
pt.RefreshTable
End Sub

I need to do this for only one pivotitem for all pivot tables on the
active sheet. I dont sem to be able to get this to work though I am
sure it is simple.

Can someone help?

Doug



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

  #3   Report Post  
 
Posts: n/a
Default

Debra,

Thanks for this. I had to modify it just a bit, but it is not changing
the field I wanted. The column name is "UPLMTH" and the new name in
the privotable is "Uplift Month" I want to change the caption (APR) to
(4) the original source data.

Here is the code I used

Sub ResetCaptions1()
'retrieve original field names
'if captions have been typed into pt

Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Dim SFld As String
SFld = "Uplift month"

For Each pt In ActiveSheet.PivotTables
Set pf = pt.PivotFields(SFld)

For Each pi In pf.PivotItems
pi.Caption = pi.SourceName
Exit For

Next pi
pt.RefreshTable
Next pt
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro with F9 Kenny Excel Discussion (Misc queries) 1 August 3rd 05 02:41 PM
Make Alignment options under format cells available as shortcut dforrest Excel Discussion (Misc queries) 1 July 14th 05 10:58 PM
Help with macro looping and color query function kevinm Excel Discussion (Misc queries) 10 May 26th 05 01:25 AM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM


All times are GMT +1. The time now is 06:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"