Solved

Pivot tables useing VBA

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

743 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

11 Experts available now in Live!

Get 1:1 Help Now