Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Pivot tables useing VBA

Posted on 2011-03-02
2
Medium Priority
?
386 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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

722 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