Select criteria in another worksheet refreshes pivot tables in other worksheets

dellzy

Board Regular
Joined
Apr 24, 2013
Messages
146
Hye Excel Experts,

This code I found seems to be really awesome. However, I couldn't get it to refresh the pivot tables automatically when I park the selection list in another worksheet. It only works when the list in the same worksheet as the pivot tables. Please help to correct the code below to meet my objective of having the list in Sheet1 but refreshed pivot tables in Sheet2.

Code:
Option Explicit


Private Sub Worksheet_Change(ByVal Target As Range)


Dim ws As Worksheet
Dim pt As PivotTable
Dim pi As PivotItem
Dim strField As String


strField = "Mth/Yr"


On Error Resume Next
Application.EnableEvents = False
Application.ScreenUpdating = False


    If Target.Address = Range("Month").Address Then
        
'        For Each ws In ThisWorkbook.Worksheets
        Set ws = Me
            For Each pt In ws.PivotTables
                With pt.PageFields(strField)
                    For Each pi In .PivotItems
                        If pi.Value = Target.Value Then
                            .CurrentPage = Target.Value
                            Exit For
                        Else
                            .CurrentPage = "(All)"
                        End If
                    Next pi
                End With
            Next pt
'        Next ws
    
    End If


Application.EnableEvents = True
Application.ScreenUpdating = True


End Sub

Thank you in advance.
DZ
 

Forum statistics

Threads
1,226,878
Messages
6,193,464
Members
453,802
Latest member
SarahNoob

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top