+ Reply to Thread
Results 1 to 3 of 3

Set up pivot table with VBA?

Hybrid View

  1. #1
    Registered User
    Join Date
    09-08-2014
    Location
    London
    MS-Off Ver
    2010
    Posts
    6

    Question Set up pivot table with VBA?

    Hello all,

    I have a couple of steps that I seem to be taking what feels like a hundred times a week when it comes to setting up pivot tables. This has made me think "isn't there a better way", but after googling around for a bit it does not look like there is any way to change the default field settings globally.

    I am now wondering if there could be a way to achieve what I want with the use of a VBA macro, but my VBA skills with this are still very very limited.

    Here is what I currently do manually:
    1. Drag in all the fields that I need (I guess that would remain a manual task as it's not always the same fields)
    2. Loop for each row label:
    2.1. Click on field settings
    2.2. In Subtotals & Filters tab, select "None" (default is automatic)
    2.3. In Layout & Print tab, select "Show item labels in tabular form" (default is "show items in outline form")
    2.4. Still in Layout & Print tab, select "Repeat item labels" (default unselected)
    2.5. Press ok
    2.6. next row label and back to 2.1. until all are done.


    I tried recording it for one field and this is what it came up with:
    Sub test()
        ActiveSheet.PivotTables("PivotTable16").PivotFields("Field Name").Subtotals = _
            Array(False, False, False, False, False, False, False, False, False, False, False, False)
        With ActiveSheet.PivotTables("PivotTable16").PivotFields("Field Name")
            .LayoutForm = xlTabular
            .RepeatLabels = True
        End With
    End Sub
    That does make some sense to me (I can identify the steps that the code is taking), but what I am not clear on in particular is how to kind of address just "whichever" pivot is on the active sheet (as this will not always be "PivotTable16") and then establish a loop for "all field names that are in the table", rather than as in this case just the example "Field Name". I hope my explanation of the problem makes sense.

    It would be fantastic if any of you who are experienced in VBA could tell me if what I am looking to do is possible and point me in the right direction. Of course if there should be a way to change the defaults without the need for VBA and I just haven't been able to find it, that would also be much appreciated!

    Thanks a lot for any help or tips,
    Jane

  2. #2
    Forum Contributor
    Join Date
    01-21-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    227

    Re: Set up pivot table with VBA?

    It would be fantastic if any of you who are experienced in VBA could tell me if what I am looking to do is possible and point me in the right direction. Of course if there should be a way to change the defaults without the need for VBA and I just haven't been able to find it, that would also be much appreciated!
    Hope this would be helpful, go to excelvbasql.com and go thru the videos in Lesson 19: Pivot Tables . Pretty good videos on coding pivot tables.
    If I've been of help, plz add reputation.

  3. #3
    Registered User
    Join Date
    09-08-2014
    Location
    London
    MS-Off Ver
    2010
    Posts
    6

    Re: Set up pivot table with VBA?

    Thanks sakmsb, I found the link helpful. I haven't fully figured it out yet but it has given me a starting point

+ 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. Replies: 6
    Last Post: 07-31-2014, 12:56 PM
  2. Collapse/Expand - Pivot table Fields - Need equivalent option in Excel VBA Pivot table
    By ragavendraph in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-07-2012, 03:00 PM
  3. Replies: 1
    Last Post: 06-22-2010, 09:10 AM
  4. Replies: 1
    Last Post: 06-20-2010, 04:00 AM
  5. Return pivot table range...not the data table, the PIVOT TABLE!
    By Air_Cooled_Nut in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-26-2008, 01:07 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