Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Pivot tables useing VBA

Posted on 2011-03-02
2
Medium Priority
?
387 Views
Last Modified: 2012-06-21
I have 2 pivoit tables that have a common data sheet. when i filter pivot 1, is it posable to filter pivot 2  using the resultes from pivit 1.

i'm asuming that this will need some codeing in VBA

The attached sheet should make it clear

filtering the pivot 1 by name and/or country I would like pivot 2 to only show those names that are visable in pivot 1

hope this is all clear
example.xlsx
0
Comment
Question by:AshridgeTechServices
2 Comments
 
LVL 10

Accepted Solution

by:
Jon von der Heyden earned 1000 total points
ID: 35024941
Perhaps this in the sheet code module (right-click Sheet2 tab > view code, then paste this into the code pane):
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
    Call AlignPivots
End Sub

Private Sub AlignPivots()
    Dim vararrVisibleNames As Variant
    Dim pvt As PivotTable
    Dim pvf As PivotField
    Dim pvi As PivotItem
    
    Application.EnableEvents = False
    
    Set pvt = Me.PivotTables("PivotTable1")
    Set pvf = pvt.ColumnFields(1)
    
    vararrVisibleNames = pvf.DataRange
    
    Set pvt = Me.PivotTables("PivotTable2")
    Set pvf = pvt.RowFields(1)
    
    For Each pvi In pvf.PivotItems
        With pvi
            .Visible = IsNumeric(Application.Match(.Value, vararrVisibleNames, 0))
        End With
    Next pvi
    
    Application.EnableEvents = True
End Sub

Open in new window


You could just write all of the code in the PivotTableUpdateEvent.  I wasn't sure how you want to call it.

Regards
Jon
0
 
LVL 1

Author Closing Comment

by:AshridgeTechServices
ID: 35028270
JONvdHeyden

Fantastic thanks, just what i needed

Much appreciated
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question