Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Pivot table field settings

Hi

I have searched the web but couldn't find what I was after.

I am trying to write a macro that will change all the fileds selected in
a range of a pivot table. The following is a macro I recorded to get an
idea of what I need to do.

Range("C4").Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields ("Sum of b")
.Function = xlCount
.NumberFormat = "0.00"
End With

How do I tell what pivottable name and assoociated Pivotfields name is
the active cell refering to or the instance within the current selected
range.

I assume I would use the current selection object looping through each
cell until it reaches the end.

ie for each .... in selection
With ActiveSheet.PivotTables(?).PivotFields(?)
.Function = xlSum
.NumberFormat = "$#,##0.00;[Red]-$#,##0.00"
End With


Any help would be appreciated



Regards


Greg
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Pivot table field settings

You can use code similar to the following:

Sub FormatSelection()
Dim c As Range
Dim rng As Range
Dim pt As PivotTable
Dim pf As PivotField

On Error Resume Next
Set rng = Selection

For Each c In rng
Set pf = c.PivotField
If Not pf Is Nothing Then
With pf
.Function = xlSum
.NumberFormat = "$#,##0.00;[Red]-$#,##0.00"
End With
End If
Next c

End Sub


Greg wrote:
Hi

I have searched the web but couldn't find what I was after.

I am trying to write a macro that will change all the fileds selected in
a range of a pivot table. The following is a macro I recorded to get an
idea of what I need to do.

Range("C4").Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields ("Sum of b")
.Function = xlCount
.NumberFormat = "0.00"
End With

How do I tell what pivottable name and assoociated Pivotfields name is
the active cell refering to or the instance within the current selected
range.

I assume I would use the current selection object looping through each
cell until it reaches the end.

ie for each .... in selection
With ActiveSheet.PivotTables(?).PivotFields(?)
.Function = xlSum
.NumberFormat = "$#,##0.00;[Red]-$#,##0.00"
End With


Any help would be appreciated



Regards


Greg



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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Pivot table field settings

Thankyou Debra

It worked a treat, will save myself and others a lot of time.


Regards


Greg



Debra Dalgleish wrote:
You can use code similar to the following:

Sub FormatSelection()
Dim c As Range
Dim rng As Range
Dim pt As PivotTable
Dim pf As PivotField

On Error Resume Next
Set rng = Selection

For Each c In rng
Set pf = c.PivotField
If Not pf Is Nothing Then
With pf
.Function = xlSum
.NumberFormat = "$#,##0.00;[Red]-$#,##0.00"
End With
End If
Next c

End Sub


Greg wrote:

Hi

I have searched the web but couldn't find what I was after.

I am trying to write a macro that will change all the fileds selected
in a range of a pivot table. The following is a macro I recorded to
get an idea of what I need to do.

Range("C4").Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields ("Sum of b")
.Function = xlCount
.NumberFormat = "0.00"
End With

How do I tell what pivottable name and assoociated Pivotfields name is
the active cell refering to or the instance within the current
selected range.

I assume I would use the current selection object looping through each
cell until it reaches the end.

ie for each .... in selection
With ActiveSheet.PivotTables(?).PivotFields(?)
.Function = xlSum
.NumberFormat = "$#,##0.00;[Red]-$#,##0.00"
End With


Any help would be appreciated



Regards


Greg




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Pivot table field settings

You're welcome! Thanks for letting me know that it helped.

Greg wrote:
Thankyou Debra

It worked a treat, will save myself and others a lot of time.


Regards


Greg



Debra Dalgleish wrote:

You can use code similar to the following:

Sub FormatSelection()
Dim c As Range
Dim rng As Range
Dim pt As PivotTable
Dim pf As PivotField

On Error Resume Next
Set rng = Selection

For Each c In rng
Set pf = c.PivotField
If Not pf Is Nothing Then
With pf
.Function = xlSum
.NumberFormat = "$#,##0.00;[Red]-$#,##0.00"
End With
End If
Next c

End Sub


Greg wrote:

Hi

I have searched the web but couldn't find what I was after.

I am trying to write a macro that will change all the fileds selected
in a range of a pivot table. The following is a macro I recorded to
get an idea of what I need to do.

Range("C4").Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields ("Sum of b")
.Function = xlCount
.NumberFormat = "0.00"
End With

How do I tell what pivottable name and assoociated Pivotfields name
is the active cell refering to or the instance within the current
selected range.

I assume I would use the current selection object looping through
each cell until it reaches the end.

ie for each .... in selection
With ActiveSheet.PivotTables(?).PivotFields(?)
.Function = xlSum
.NumberFormat = "$#,##0.00;[Red]-$#,##0.00"
End With


Any help would be appreciated



Regards


Greg







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

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
Pivot table value (field settings) isamel Excel Discussion (Misc queries) 0 March 7th 08 10:04 PM
pivot table field settings % of... Colin Funk Excel Worksheet Functions 0 May 3rd 07 11:44 PM
Pivot table field settings Siew-Ming Excel Programming 5 August 15th 05 08:23 PM
Pivot Table Field Settings Pivot Novice Excel Worksheet Functions 5 July 13th 05 01:40 AM
Pivot Table Field Settings Michael Excel Programming 0 April 12th 05 08:35 PM


All times are GMT +1. The time now is 12:16 PM.

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

About Us

"It's about Microsoft Excel"