+ Reply to Thread
Results 1 to 3 of 3

Macro code for settings

  1. #1
    Forum Contributor
    Join Date
    11-02-2003
    Location
    Birmingham, UK
    MS-Off Ver
    Office 365
    Posts
    127

    Macro code for settings

    Almost every pivot table I do, I have to manually alter the following settings using the menu bar.

    Subtotals - Set to 'Do not show subtotals
    Grand Totals - Set to 'Off for Rows and Columns'
    Report Layout - Set to 'Show in Tabular Form'

    I tried recording these steps into a Macro with no success. Are there any Macro steps I can use ?

    If not, is there a way that I can set all my Pivots to start with the above setup ?

    Hope someone can help.

    Thanks

    Tdub
    Terry

    "... I thought I was a power user of Excel until I came onto these boards..."

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Macro code for settings

    Hi,

    Searching the net, it looks like Power Pivots might give you a chance.

    https://support.office.com/en-us/art...0-91F5140A4F25

    Other than writing VBA, I don't see a way.
    I've recorded a macro to do your above steps and it keys on the single pivot table and then each field to do the settings. In VBA a "For Each" loop might generalize these steps but we should have a sample file to do it with.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor
    Join Date
    11-02-2003
    Location
    Birmingham, UK
    MS-Off Ver
    Office 365
    Posts
    127

    Re: Macro code for settings

    Thank you for looking at this Marvin. You're right I think VBA is the way to go. I've found two pieces of code which do No Subtotals or Grand Totals. So I'm 2/3rds of the way there..

    I've got the tabular row code I think. I'm just scratching my head now to include this in a macro that does all 3 tasks on the current pivot table.

    ActiveSheet.PivotTables("PivotTable1").RowAxisLayout xlTabularRow

    Here is the code for the Hide subtotals and grand totals. They both work
    Sub PivotTableLayout()
    Dim PvtTbl As PivotTable
    Dim pvtFld As PivotField

    Set PvtTbl = ActiveSheet.PivotTables(1)

    'hide Subtotals for all fields in the PivotTable .

    With PvtTbl
    For Each pvtFld In .PivotFields
    pvtFld.Subtotals(1) = True
    pvtFld.Subtotals(1) = False
    Next pvtFld
    End With
    End Sub


    Sub PivotGrandTotals()
    'PURPOSE: Show setup for various Pivot Table Grand Total options
    'SOURCE: www.TheSpreadsheetGuru.com

    Dim pvt As PivotTable

    Set pvt = ActiveSheet.PivotTables(1)

    'Off for Rows and Columns
    pvt.ColumnGrand = False
    pvt.RowGrand = False

    'On for Rows and Columns
    'pvt.ColumnGrand = True
    'pvt.RowGrand = True

    'On for Rows only
    'pvt.ColumnGrand = False
    'pvt.RowGrand = True

    'On for Columns Only
    'pvt.ColumnGrand = True
    'pvt.RowGrand = False

    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Can I write code that can get VBE settings?
    By kadeo in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-09-2015, 06:03 AM
  2. [SOLVED] Record macro -change settings where the macro is stored
    By Masun in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-07-2014, 01:52 AM
  3. VBA Code to modify printer duplex settings for one Sheet of a workbook
    By ben.collins in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-04-2012, 08:45 AM
  4. VBA Code to setup print settings for all worksheets within a work book.
    By anfdrew in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-23-2012, 09:58 PM
  5. [SOLVED] One of the Settings in Options Trust Center Settings is Grayed out
    By zit1343 in forum Excel General
    Replies: 2
    Last Post: 06-28-2012, 09:18 AM
  6. Writing code to modify the settings ?
    By aca in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-26-2009, 02:04 PM
  7. VB code changed Excel settings for all worksheets
    By JenniferMc in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-15-2005, 04:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1