Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default How to replace PivotTable data fields...?


This snippet works in xl97 AND xlXP (sorry can't test xl2k)
it's as flexible as possible as it avoids "hardcoding"...

datafields are added last to avoid maximum size..

you'll need sheets "data" and "pivots"


ActiveWorkbook.Names.Add "dnPivSource", _
"=OFFSET(Data!$A$1,0,0,COUNTA(Data!$A:$A),COUNTA(D ata!$1:$1))"

heads = [dnPivSource].Resize(1)

On Error Resume Next
Worksheets("Pivots").PivotTables("Pivot1").TableRa nge2.Clear
On Error GoTo 0

Set pt = ActiveWorkbook.PivotCaches.Add(xlDatabase, _
"dnPivSource").CreatePivotTable([Pivots!A1], "Pivot1")
With pt
For Each pf In .VisibleFields
pf.Orientation = xlHidden
Next
.AddFields _
RowFields:=Array(heads(1, 1), heads(1, 2)), _
ColumnFields:=Array(heads(1, 3)), _
PageFields:=Array(heads(1, 4))
.PivotFields(heads(1, 5)).Orientation = xlDataField
.DataFields(1).Function = xlSum
.DataFields(1).Name = "Top5"
.RowFields(1).AutoSort xlDescending, .DataFields(1).Name
.RowFields(1).AutoShow xlAutomatic, xlTop, 5,.DataFields(1).Name
.RowFields(1).Subtotals(1) = False
End With


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


DaveGulliksen wrote:

I, too, have been struggling with the same problem in Excel 2000.

I've recorded a macro where I've dragged a field into the DataField
area and pulled it back out again to hide it, but when I try to play
the macro back, it fails with the message "Unable to set the
Orientation property of the PivotField class". Here's the code:

Sub Macro8()

With ActiveSheet.PivotTables("PivotTable1").PivotFields ("EndBal")
Orientation = xlDataField
Position = 1
End With

ActiveSheet.PivotTables("PivotTable1").PivotFields ("Count of
EndBal").Orientation = xlHidden <====== FAILS HERE (also fails with
"EndBal" instead of "Count of EndBal")

End Sub

So far, the only workaround that seems to do the job is to delete the
cell with the fieldname in it: Range("A4").Delete

Of course, you have to figure out which cell has the field header in

it
in order to delete it. Have you found any other way to do it?

Dave G



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from

http://www.ExcelForum.com/


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
2003 PIvotTable Calculated Fields Kay Excel Discussion (Misc queries) 3 April 24th 10 06:41 PM
Linking PivotTable Fields - Excel 2007 Jim Excel Discussion (Misc queries) 1 August 6th 09 09:57 PM
Pivottable Sum of fields. Saviz Excel Discussion (Misc queries) 1 July 17th 08 12:10 PM
pivottable calculated fields HelpAl Excel Discussion (Misc queries) 3 December 8th 05 10:18 PM
PivotTable - Unchecking and re-checking data fields Jeff K Excel Discussion (Misc queries) 1 July 20th 05 09:36 PM


All times are GMT +1. The time now is 11:11 AM.

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"