Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

9/26/2020 Turn off Pivot subtotals [SOLVED]

Welcome, Dachacal Notifications My Profile Settings Log Out

Forum What's New? Members List Calendar Forum Rules Dashboard

New Posts My Services


Commercial Posts FAQ Calendar Community Forum Actions Quick Links Advanced Search

Forum Microsoft Office Application Help - Excel Help forum


Excel Programming / VBA / Macros [SOLVED] Turn off Pivot subtotals

Dachacal, You are member of Excel Help Forum for 1 day(s) now but haven't posted anything
yet. How about introducing yourself to the rest of the users? Click on this message bar if you wish
to make an introduction thread now. If you wish to post a question, please choose the relevant
sub-forum.

HOW TO ATTACH YOUR SAMPLE WORKBOOK:


Dachacal Fast answers need clear examples. Post a small Excel sheet (not a picture) showing realistic &
representative sample data WITHOUT confidential information (10-20 rows, not thousands...) and some manually
calculated results. Just before posting, scroll down to GO ADVANCED, click, and then scroll down to MANAGE
ATTACHMENTS and click again. Now follow the instructions at the top of that screen.

Results 1 to 11 of 11
+ Reply to Thread
Turn off Pivot subtotals

LinkBack Thread Tools Search Thread Rate This Thread Display

07-27-2017, 04:49 PM #1

jomili
Turn off Pivot subtotals
Valued Forum Contributor
Weirdest thing; I've been using the below macro for a couple
Join Date: 12-02-2009 of years with no problem. Today it's still working fine for one
Location: Austin, Tx file, but for another I get an error 1004: "Unable to set the
MS-Off Ver: Excel 2016 Office 365 Subtotals property of the PivotField class" at the area noted
64-Bit below. I can't post the WB because the Pivot is based on a
Posts: 3,400 remote data source and it's privileged information (and
huge). I'd be glad to post an example, but the code works
fine on that data. it fails on the "True" line. Help!

End With
On Error GoTo 0
Set PF = GetBudAcctField(PT)
If Not PF Is Nothing Then
With PF
.Orientation = xlPageField
.Position = 5
End With
End If
With .PivotFields("STRATEGY")
.Orientation = xlPageField
.Position = 5
End With
.ColumnGrand = False
.RowGrand = False
.RepeatAllLabels xlRepeatLabels
.ManualUpdate = False
https://www.excelforum.com/excel-programming-vba-macros/1194634-turn-off-pivot-subtotals.html 1/7
9/26/2020 Turn off Pivot subtotals [SOLVED]
.ManualUpdate False
'Turn off subtotals
For Each PF In .PivotFields
'Set index 1 (Automatic) to True,
'so all other values are set to False
PF.Subtotals(1) = True
PF.Subtotals(1) = False
Next PF
Stop
End With
Exit Sub
Bailout:
MsgBox "The Open Year Summary can't be refreshed rig
"Please try again later.", vbOKOnly + vbInformation,
WbSrc.Close False
SpeedOff
Exit Sub

Last edited by jomili; 07-27-2017 at 04:52 PM. Reason: more detail


I know I'm not stupid, but I suspect I'm a lot stupider than I think I
am
Report Post Reply With Quote

07-27-2017, 05:09 PM #2

jeffreybrown
Re: Turn off Pivot subtotals
Forum Moderator
I've been using the below macro for a couple of years
with no problem
Join Date: 02-19-2009 I suspect, if its been working for years and the only thing
Location: Cibolo, TX different is a new workbook, then don't you think it's the
MS-Off Ver: Excel 2016 workbook and not the code?
Posts: 10,052
If we can't see the workbook (and understandable why), then
it's going to be hard to diagnose any problem.

HTH
Regards, Jeff

Report Post Reply With Quote

07-27-2017, 05:38 PM #3

MarvinP
Re: Turn off Pivot subtotals
Forum Guru
Hey,

Can you do your pivot table by hand? When this happens to


me, I find there are no values in the pivot or one of the
Join Date: 07-22-2010

https://www.excelforum.com/excel-programming-vba-macros/1194634-turn-off-pivot-subtotals.html 2/7
9/26/2020 Turn off Pivot subtotals [SOLVED]
Location: Woodinville, WA names has changed. Do it by hand and see what changed
MS-Off Ver: Office 365 from the last time you did it.
Posts: 15,249

One test is worth a thousand opinions.


Click the * Add Reputation below to say thanks.

Report Post Reply With Quote

07-28-2017, 07:20 AM #4

jomili
Re: Turn off Pivot subtotals
Valued Forum Contributor
Good suggestion, but no joy. If I stop the macro right before
Join Date: 12-02-2009 the "Subtotals" set, then manually go to Design/Subtotals/Do
Location: Austin, Tx Not Show subtotals it works just fine. But if I try the macro to
MS-Off Ver: Excel 2016 Office 365 turn off the subtotals I get the error.
64-Bit
Posts: 3,400 Just tried it this morning again, by isolating the "subtotal"
part of the macro (see code below). Opened WB, made no
changes to the Pivot, manually turned off subtotals,
everything's great. Closed without saving. Reopened, ran
macro below. Error.

I know it's not much help, but I'm attaching screenshots of


the two pivots, each of which is in it's own workbook. The
2017 is the one that's causing trouble.

EDIT: just had a thought. The error occurs on the


"PF.Subtotals(1) = True" line. Maybe there's a PivotField in
the list that doesn't exist in the pivot, so can't be turned to
true. How would I find that?

Sub Filter_Pivot()
Dim PF As PivotField
Dim PI As PivotItem
Dim PT As PivotTable
Set PT = ActiveSheet.PivotTables(1)
SpeedOn
With PT
'Turn off subtotals
For Each PF In .PivotFields
'Set index 1 (Automatic) to True,
'so all other values are set to False
PF.Subtotals(1) = True
PF.Subtotals(1) = False
Next PF
End With
SpeedOff
End Sub

Sub SpeedOn(Optional StatusBarMsg As String = "Jorge


With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
.Cursor = xlWait
.StatusBar = StatusBarMsg
.EnableCancelKey = xlErrorHandler
End With
End Sub
Sub SpeedOff()

https://www.excelforum.com/excel-programming-vba-macros/1194634-turn-off-pivot-subtotals.html 3/7
9/26/2020 Turn off Pivot subtotals [SOLVED]
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
E bl E t T

Attached Images
Problem Piv.PNG (59.0 KB, 38 views)
Download
Trouble Free Piv.PNG (59.3 KB, 39 views)
Download

Last edited by jomili; 07-28-2017 at 07:23 AM. Reason: Extra thought.


Report Post Reply With Quote

07-28-2017, 07:36 AM #5

xlnitwit
Re: Turn off Pivot subtotals
Forum Guru
Since setting it to True fails, why not use

.Subtotals = Array(False, False, False, False, False

Join Date: 06-27-2016


Location: London
MS-Off Ver: Windows: 2010; Mac:
16.13 (O365) instead of the toggle approach? You can also turn them all off
Posts: 7,083 at once using

Application.CommandBars.ExecuteMso "PivotTableSubtota

as long as you have selected a cell in the pivot table.

Don
Please remember to mark your thread 'Solved' when appropriate.

Report Post Reply With Quote

07-28-2017, 07:50 AM #6

jomili
Re: Turn off Pivot subtotals
Valued Forum Contributor
Tried the first option like this, got the same error:
Join Date: 12-02-2009
Location: Austin, Tx
MS-Off Ver: Excel 2016 Office 365 Sub Filter_Pivot()
Dim PF As PivotField
64-Bit
Dim PI As PivotItem
Posts: 3,400 Dim PT As PivotTable
https://www.excelforum.com/excel-programming-vba-macros/1194634-turn-off-pivot-subtotals.html 4/7
9/26/2020 Turn off Pivot subtotals [SOLVED]
Set PT = ActiveSheet.PivotTables(1)
SpeedOn
With PT
'Turn off subtotals
For Each PF In .PivotFields
PF.Subtotals = Array(False, False, False, Fa
'Set index 1 (Automatic) to True,
'so all other values are set to False
' PF.Subtotals(1) = True
' PF.Subtotals(1) = False
Next PF
End With
SpeedOff
End Sub

Trying this, it works. But why won't the other two work?

Sub Filter_Pivot()
Dim PF As PivotField
Dim PI As PivotItem
Dim PT As PivotTable
Set PT = ActiveSheet.PivotTables(1)
SpeedOn
ActiveSheet.Range("A5").Select
With PT
'Turn off subtotals
Application.CommandBars.ExecuteMso "PivotTableSubtota
' For Each PF In .PivotFields
' PF.Subtotals = Array(False, False, False, Fa
'Set index 1 (Automatic) to True,
'so all other values are set to False
' PF.Subtotals(1) = True
' PF.Subtotals(1) = False
' Next PF
End With
SpeedOff
End Sub

Report Post Reply With Quote

08-21-2019, 02:03 AM #7

pete22k
Re: Turn off Pivot subtotals
Registered User
when i tried the second option which has the following code
Join Date: 08-21-2019 for Pivot Table donot show subtotals
Location: AZ,USA
MS-Off Ver: 2013
Posts: 3
Application.CommandBars.ExecuteMso "PivotTableSubtota

it is throwing -2147467259 automation error , can you


suggest how to resolve this error

Report Post Reply With Quote

08-21-2019, 04:14 AM #8

https://www.excelforum.com/excel-programming-vba-macros/1194634-turn-off-pivot-subtotals.html 5/7
9/26/2020 Turn off Pivot subtotals [SOLVED]

rorya
Re: Turn off Pivot subtotals
Forum Expert
Did you select a cell in the pivot table first, as xlnitwit
mentioned?

Join Date: 08-13-2008


Location: UK
MS-Off Ver: 2016 primarily
Posts: 4,694

Rory
Yea though I walk through the valley of the shadow of death, at least
it's a change of scenery
Report Post Reply With Quote

08-21-2019, 10:18 AM #9

pete22k
Re: Turn off Pivot subtotals
Registered User
yes i did select pivot table it begins from cell 23, not sure of
Join Date: 08-21-2019 xlnitwit method
Location: AZ,USA
MS-Off Ver: 2013
Posts: 3

wrkSht.Range("B23").Select
On Error Resume Next
Set pt = wrkSht.PivotTables("PivotTable1")
On Error GoTo 0

If Not pt Is Nothing Then


Application.CommandBars.ExecuteMso "PivotTab
pt.RowGrand = False
pt.ColumnGrand = False
pt.RowAxisLayout xlTabularRow
pt.RepeatAllLabels xlRepeatLabels
End If

Report Post Reply With Quote

08-21-2019, 11:28 AM #10

jomili
Re: Turn off Pivot subtotals
Valued Forum Contributor
pete22k, can you upload a copy of your pivot workbook so we
Join Date: 12-02-2009 can take a look?
Location: Austin, Tx
MS-Off Ver: Excel 2016 Office 365
64-Bit
Posts: 3,400

Report Post Reply With Quote

08-21-2019, 05:14 PM #11

pete22k
Re: Turn off Pivot subtotals
https://www.excelforum.com/excel-programming-vba-macros/1194634-turn-off-pivot-subtotals.html 6/7
9/26/2020 Turn off Pivot subtotals [SOLVED]
Registered User
This solution is working fine, i was getting error this place due
Join Date: 08-21-2019 to wrong placement of code. Thanks to xlnitwit who posted
Location: AZ,USA the solution & rorya for giving the pointer
MS-Off Ver: 2013
Posts: 3

Report Post Reply With Quote

+ Reply to Thread

« Previous Thread | Next Thread »

Thread Information
There are currently 1 users browsing this thread. (1 members and 0 guests)
Dachacal

Similar Threads
[SOLVED] VBA code to turn data into pivot table and then into pivot chart Replies: 1
By Faintkitara in forum Excel Programming / VBA / Macros Last Post: 05-25-2015, 08:05 PM

subtotals and pivot tables Replies: 3


By whenweescape in forum Excel General Last Post: 02-22-2014, 10:30 PM

Subtotals in Pivot Tables Replies: 4


By rtabaldi in forum Excel General Last Post: 06-27-2011, 01:09 PM

how to stop subtotals in Pivot Tbl Replies: 1


By dpenny in forum Excel General Last Post: 07-21-2006, 04:40 PM

[SOLVED] Pivot Table subtotals Replies: 1


By Matt M HMS in forum Excel General Last Post: 06-02-2006, 07:45 PM

Pivot table subtotals Replies: 2


By RhysPieces in forum Excel General Last Post: 05-04-2006, 11:00 AM

[SOLVED] Pivot Table subtotals Replies: 1


By Linda in forum Excel Formulas & Functions Last Post: 02-08-2005, 08:06 PM

Bookmarks Posting Permissions


Digg You may not post new BB code is On
threads Smilies are On
del.icio.us
You may not post replies [IMG] code is Off
StumbleUpon You may not post HTML code is Off
attachments Trackbacks are Off
Google
You may not edit your Pingbacks are Off
posts Refbacks are On
Forum Rules

-- vB4 Default Style Contact Us ExcelForum.com Archive Top

All times are GMT -5. The time now is 06:53 AM.

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1

https://www.excelforum.com/excel-programming-vba-macros/1194634-turn-off-pivot-subtotals.html 7/7

You might also like