Andre Costa
New Member
- Joined
- Jan 23, 2014
- Messages
- 5
</SPAN></SPAN></SPAN></SPAN><o>Hello all! =D
I'm trying to create a vba code to automaticaly put all the fields and formats to my pivot tables to speed up my analysis. I'm having problems with the final part where I want to disable the subtotals... The full version of the code is at the end of the message, and I'm having problems with the final lines:
For Each pf In pvt.PivotFields
With pvt
.Subtotals(pf) = False
End With
Next pf
wich do not work properly...
I would love to hear your solutions =)
Thanks a lot in advance,
André
The full code:
Sub Pivot_Stocks()
Dim wks As Worksheet<u1></u1>
Dim pvt As PivotTable<u1></u1>
Dim pf As PivotField<u1></u1>
<u1></u1>For Each wks In Worksheets<u1></u1>
For Each pvt In wks.PivotTables<u1></u1>
<u1></u1>pvt.ClearTable
'Column Labels<u1></u1>
With pvt.PivotFields("Date")<u1></u1>
.Orientation = xlColumnField<u1></u1>
.Position = 1<u1></u1>
End With<u1></u1>
<u1></u1>'Row Labels<u1></u1>
With pvt.PivotFields("stock_ticker")<u1></u1>
.Orientation = xlRowField<u1></u1>
.Position = 1<u1></u1>
End With<u1></u1>
With pvt.PivotFields("Stock_name")<u1></u1>
.Orientation = xlRowField<u1></u1>
.Position = 2<u1></u1>
End With<u1></u1>
<u1></u1>'Report Filter<u1></u1>
With pvt.PivotFields("Stock_exchange")<u1></u1>
.Orientation = xlPageField<u1></u1>
.Position = 1<u1></u1>
End With<u1></u1>
With pvt.PivotFields("Country")<u1></u1>
.Orientation = xlPageField<u1></u1>
.Position = 2<u1></u1>
End With<u1></u1>
<u1></u1>'Sum of Values<u1></u1>
pvt.AddDataField pvt.PivotFields("Price"), _<u1></u1>
"Sum of Price", xlSum<u1></u1>
pvt.AddDataField pvt.PivotFields("Volume"), _<u1></u1>
"Sum of Volume", xlSum<u1></u1>
<u1></u1>With pvt<u1></u1>
.ColumnGrand = False<u1></u1>
.RowGrand = False<u1></u1>
End With <u1></u1>
<u1></u1>pvt.RowAxisLayout xlTabularRow <u1></u1>
<u1></u1>For Each pf In pvt.PivotFields<u1></u1>
With pvt<u1></u1>
.Subtotals(pf) = False<u1></u1>
End With<u1></u1>
Next pf<u1></u1>
<u1></u1>Next pvt<u1></u1>
Next wks<u1></u1>
<u1></u1>End Sub <u1></u1><o></o>
</o></SPAN>
I'm trying to create a vba code to automaticaly put all the fields and formats to my pivot tables to speed up my analysis. I'm having problems with the final part where I want to disable the subtotals... The full version of the code is at the end of the message, and I'm having problems with the final lines:
For Each pf In pvt.PivotFields
With pvt
.Subtotals(pf) = False
End With
Next pf
wich do not work properly...
I would love to hear your solutions =)
Thanks a lot in advance,
André
The full code:
Sub Pivot_Stocks()
Dim wks As Worksheet<u1></u1>
Dim pvt As PivotTable<u1></u1>
Dim pf As PivotField<u1></u1>
<u1></u1>For Each wks In Worksheets<u1></u1>
For Each pvt In wks.PivotTables<u1></u1>
<u1></u1>pvt.ClearTable
'Column Labels<u1></u1>
With pvt.PivotFields("Date")<u1></u1>
.Orientation = xlColumnField<u1></u1>
.Position = 1<u1></u1>
End With<u1></u1>
<u1></u1>'Row Labels<u1></u1>
With pvt.PivotFields("stock_ticker")<u1></u1>
.Orientation = xlRowField<u1></u1>
.Position = 1<u1></u1>
End With<u1></u1>
With pvt.PivotFields("Stock_name")<u1></u1>
.Orientation = xlRowField<u1></u1>
.Position = 2<u1></u1>
End With<u1></u1>
<u1></u1>'Report Filter<u1></u1>
With pvt.PivotFields("Stock_exchange")<u1></u1>
.Orientation = xlPageField<u1></u1>
.Position = 1<u1></u1>
End With<u1></u1>
With pvt.PivotFields("Country")<u1></u1>
.Orientation = xlPageField<u1></u1>
.Position = 2<u1></u1>
End With<u1></u1>
<u1></u1>'Sum of Values<u1></u1>
pvt.AddDataField pvt.PivotFields("Price"), _<u1></u1>
"Sum of Price", xlSum<u1></u1>
pvt.AddDataField pvt.PivotFields("Volume"), _<u1></u1>
"Sum of Volume", xlSum<u1></u1>
<u1></u1>With pvt<u1></u1>
.ColumnGrand = False<u1></u1>
.RowGrand = False<u1></u1>
End With <u1></u1>
<u1></u1>pvt.RowAxisLayout xlTabularRow <u1></u1>
<u1></u1>For Each pf In pvt.PivotFields<u1></u1>
With pvt<u1></u1>
.Subtotals(pf) = False<u1></u1>
End With<u1></u1>
Next pf<u1></u1>
<u1></u1>Next pvt<u1></u1>
Next wks<u1></u1>
<u1></u1>End Sub <u1></u1><o></o>
</o></SPAN>