Disable subtotals (with a loop)

Andre Costa

New Member
Joined
Jan 23, 2014
Messages
5
</SPAN></SPAN></SPAN></SPAN><o:p>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:p></u1:p>
Dim pvt As PivotTable<u1:p></u1:p>
Dim pf As PivotField<u1:p></u1:p>

<u1:p></u1:p>
For Each wks In Worksheets<u1:p></u1:p>
For Each pvt In wks.PivotTables<u1:p></u1:p>

<u1:p></u1:p>
pvt.ClearTable

'Column Labels<u1:p></u1:p>
With pvt.PivotFields("Date")<u1:p></u1:p>
.Orientation = xlColumnField<u1:p></u1:p>
.Position = 1<u1:p></u1:p>
End With<u1:p></u1:p>

<u1:p></u1:p>
'Row Labels<u1:p></u1:p>
With pvt.PivotFields("stock_ticker")<u1:p></u1:p>
.Orientation = xlRowField<u1:p></u1:p>
.Position = 1<u1:p></u1:p>
End With<u1:p></u1:p>
With pvt.PivotFields("Stock_name")<u1:p></u1:p>
.Orientation = xlRowField<u1:p></u1:p>
.Position = 2<u1:p></u1:p>
End With<u1:p></u1:p>

<u1:p></u1:p>
'Report Filter<u1:p></u1:p>
With pvt.PivotFields("Stock_exchange")<u1:p></u1:p>
.Orientation = xlPageField<u1:p></u1:p>
.Position = 1<u1:p></u1:p>
End With<u1:p></u1:p>
With pvt.PivotFields("Country")<u1:p></u1:p>
.Orientation = xlPageField<u1:p></u1:p>
.Position = 2<u1:p></u1:p>
End With<u1:p></u1:p>

<u1:p></u1:p>
'Sum of Values<u1:p></u1:p>
pvt.AddDataField pvt.PivotFields("Price"), _<u1:p></u1:p>
"Sum of Price", xlSum<u1:p></u1:p>
pvt.AddDataField pvt.PivotFields("Volume"), _<u1:p></u1:p>
"Sum of Volume", xlSum<u1:p></u1:p>

<u1:p></u1:p>
With pvt<u1:p></u1:p>
.ColumnGrand = False<u1:p></u1:p>
.RowGrand = False<u1:p></u1:p>
End With <u1:p></u1:p>

<u1:p></u1:p>
pvt.RowAxisLayout xlTabularRow <u1:p></u1:p>

<u1:p></u1:p>
For Each pf In pvt.PivotFields<u1:p></u1:p>
With pvt<u1:p></u1:p>
.Subtotals(pf) = False<u1:p></u1:p>
End With<u1:p></u1:p>
Next pf<u1:p></u1:p>

<u1:p></u1:p>
Next pvt<u1:p></u1:p>
Next wks<u1:p></u1:p>

<u1:p></u1:p>
End Sub <u1:p></u1:p><o:p></o:p>
</o:p>
</SPAN>
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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
Back
Top