+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    05-09-2008
    Posts
    4

    Smile VBA Code which mirrors changes on one pivot onto a second pivot

    Hi,

    I can't see why the following VBA code won't work - is that always the case. I have two pivot tables on one sheet. I have hidden most of the second pivot table which includes the fields to filter by. The two pivots use the same four fields so I want a change made to one of the fields on the main pivot to also chaneg the data on the second.

    The code I have written compiles but the pivot seems to flash for a split second with the correct change and reverts to its orginal.

    e.g If I change FinYear to 2009/10 in my main pivot the second pivot flashes briefly with 2009/10 and then reverts to 2008/09.

    I have attached my code as a text file to make my post shorter. it's quite simple...or should be.

    If you would prefer I post it in full here, let me know.

    I would apprecate any and all help.
    Attached Files Attached Files

  2. #2
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: VBA Code which mirrors changes on one pivot onto a second pivot

    Without seeing the files etc it's obviously hard to comment but as I see it you're only ever referring to pt1

    Code:
    Set pt1 = ws.PivotTables("RIW2")
    which we assume relates to 2nd pivot...

    however, you're then using an approach of:

    Code:
       mvAT = pt1.PivotFields(strField1).CurrentPage
     
       With pt1.PageFields(strField1)
            .CurrentPage = "(All)"
            For Each pi In .PivotItems
                If pi.Value = mvAT Then
                 .CurrentPage = mvAT
                   Exit For
                End If
            Next pi
        End With
    all this will do is go to All and then revert to original setting... you should I think be basing mVAT off Target rather than pt1....ie:

    Code:
    mvAT = Target.PivotFields(strField1).CurrentPage
    in the above we're assuming you're only setting filters via 1st Pivot - it's not an either/or affair.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0