Solved

Pivot tables useing VBA

Posted on 2011-03-02
2
380 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 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

947 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now