+ Reply to Thread
Results 1 to 2 of 2

Pivot Table recalculations

  1. #1
    C0ppert0p
    Guest

    Pivot Table recalculations

    Hi All,
    I have a VB macro that builds a Pivot table after reading in a csv
    file.
    When I recorded the macro, I selected only certain values from multiple
    pivot fields to display but the macro records it this way:

    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Type*")
    .PivotItems("Printer Desk Jet").Visible = False
    .PivotItems("Printer Document Center").Visible = False
    .PivotItems("Printer Ink Jet").Visible = False

    Yep, it chooses what I don't want to display. This PivotField has over
    500 values of which I only want to display ten and I have five
    PivotFields I want to select from.

    When I replay the macro the PivotTable get recalculated for every one
    of the statements

    There has to be a better way of doing this. Any suggestions.

    Thanks in advance.


  2. #2
    C0ppert0p
    Guest

    Re: Pivot Table recalculations

    Got it:
    I found a great solution written by Debra Dalgleish:

    You could use code similar to the following:
    Sub HidePivotItems()
    'hide all pivot items in all tables on sheet
    'except specified item

    Dim pt As PivotTable
    Dim pf As PivotField
    Dim pi As PivotItem

    On Error Resume Next
    For Each pt In ActiveSheet.PivotTables
    Set pf = pt.PivotFields("Role")
    pf.AutoSort xlManual, "Role"
    For Each pi In pf.PivotItems
    If pi.Value = "Painter" Then
    pi.Visible = True
    Else
    pi.Visible = False
    End If
    Next
    pf.AutoSort xlAscending, "Role"
    Next
    End Sub


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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