Solved

Pivot tables useing VBA

Posted on 2011-03-02
2
385 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: 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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

622 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