I have this code below to where I select a name in cell I4, and then click run in cell f4, and this filters to that name in each pivot table on the page. This always worked before but all of a sudden stopped working?
Also, is there a way I can write this to where if you just select another name in cell I4, that it automatically updates the pivot tables instead of having to push it to run with another cell?
Also, is there a way I can write this to where if you just select another name in cell I4, that it automatically updates the pivot tables instead of having to push it to run with another cell?
Code:
Private Sub Worksheet_PivotTableAfterValueChange(ByVal TargetPivotTable As PivotTable, ByVal TargetRange As Range)
'This line stops the worksheet updating on every change, it only updates when cells are touched
If Intersect(Target, Range("I4")) Is Nothing Then Exit Sub
'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String
'Here you amend to suit your data. Assigns input cell value to the PT on another tab.
Set pt = Worksheets("MOEVM Summary Level").PivotTables("VLQP")
Set Field = pt.PivotFields("MOEVM")
NewCat = Worksheets("MOEVM Summary Level").Range("F4").Value
'This updates and refreshes the PIVOT table
With Field
.ClearAllFilters
On Error Resume Next
.CurrentPage = NewCat
End With
Set pt = Worksheets("MOEVM Summary Level").PivotTables("DeliverablesDue")
Set Field = pt.PivotFields("MOEVM")
NewCat = Worksheets("MOEVM Summary Level").Range("F4").Value
'This updates and refreshes the PIVOT table
With Field
.ClearAllFilters
On Error Resume Next
.CurrentPage = NewCat
End With
Set pt = Worksheets("MOEVM Summary Level").PivotTables("Issues")
Set Field = pt.PivotFields("MOEVM")
NewCat = Worksheets("MOEVM Summary Level").Range("F4").Value
'This updates and refreshes the PIVOT table
With Field
.ClearAllFilters
On Error Resume Next
.CurrentPage = NewCat
End With
Set pt = Worksheets("MOEVM Summary Level").PivotTables("upcomingdeliverables")
Set Field = pt.PivotFields("MOEVM")
NewCat = Worksheets("MOEVM Summary Level").Range("F4").Value
'This updates and refreshes the PIVOT table
With Field
.ClearAllFilters
On Error Resume Next
.CurrentPage = NewCat
End With
Set pt = Worksheets("MOEVM Summary Level").PivotTables("upcomingvlqp")
Set Field = pt.PivotFields("MOEVM")
NewCat = Worksheets("MOEVM Summary Level").Range("F4").Value
'This updates and refreshes the PIVOT table
With Field
.ClearAllFilters
On Error Resume Next
.CurrentPage = NewCat
End With
Set pt = Worksheets("MOEVM Summary Level").PivotTables("DeliverPastDue")
Set Field = pt.PivotFields("MOEVM")
NewCat = Worksheets("MOEVM Summary Level").Range("F4").Value
'This updates and refreshes the PIVOT table
With Field
.ClearAllFilters
On Error Resume Next
.CurrentPage = NewCat
End With
Set pt = Worksheets("MOEVM Summary Level").PivotTables("VLQPPastDue")
Set Field = pt.PivotFields("MOEVM")
NewCat = Worksheets("MOEVM Summary Level").Range("F4").Value
'This updates and refreshes the PIVOT table
With Field
.ClearAllFilters
On Error Resume Next
.CurrentPage = NewCat
End With
Set pt = Worksheets("MOEVM Summary Level").PivotTables("Issues")
Set Field = pt.PivotFields("MOEVM")
NewCat = Worksheets("MOEVM Summary Level").Range("F4").Value
'This updates and refreshes the PIVOT table
With Field
.ClearAllFilters
On Error Resume Next
.CurrentPage = NewCat
End With
Set pt = Worksheets("MOEVM Summary Level").PivotTables("IssuesPastDue")
Set Field = pt.PivotFields("MOEVM")
NewCat = Worksheets("MOEVM Summary Level").Range("F4").Value
'This updates and refreshes the PIVOT table
With Field
.ClearAllFilters
On Error Resume Next
.CurrentPage = NewCat
End With
End Sub
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'This line stops the worksheet updating on every change, it only updates when cells are touched
If Intersect(Target, Range("I4")) Is Nothing Then Exit Sub
'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String
'Here you amend to suit your data. Assigns input cell value to the PT on another tab.
Set pt = Worksheets("MOEVM Summary Level").PivotTables("VLQP")
Set Field = pt.PivotFields("MOEVM")
NewCat = Worksheets("MOEVM Summary Level").Range("F4").Value
'This updates and refreshes the PIVOT table
With Field
.ClearAllFilters
On Error Resume Next
.CurrentPage = NewCat
End With
Set pt = Worksheets("MOEVM Summary Level").PivotTables("DeliverablesDue")
Set Field = pt.PivotFields("MOEVM")
NewCat = Worksheets("MOEVM Summary Level").Range("F4").Value
'This updates and refreshes the PIVOT table
With Field
.ClearAllFilters
On Error Resume Next
.CurrentPage = NewCat
End With
Set pt = Worksheets("MOEVM Summary Level").PivotTables("Issues")
Set Field = pt.PivotFields("MOEVM")
NewCat = Worksheets("MOEVM Summary Level").Range("F4").Value
'This updates and refreshes the PIVOT table
With Field
.ClearAllFilters
On Error Resume Next
.CurrentPage = NewCat
End With
Set pt = Worksheets("MOEVM Summary Level").PivotTables("upcomingdeliverables")
Set Field = pt.PivotFields("MOEVM")
NewCat = Worksheets("MOEVM Summary Level").Range("F4").Value
'This updates and refreshes the PIVOT table
With Field
.ClearAllFilters
On Error Resume Next
.CurrentPage = NewCat
End With
Set pt = Worksheets("MOEVM Summary Level").PivotTables("upcomingvlqp")
Set Field = pt.PivotFields("MOEVM")
NewCat = Worksheets("MOEVM Summary Level").Range("F4").Value
'This updates and refreshes the PIVOT table
With Field
.ClearAllFilters
On Error Resume Next
.CurrentPage = NewCat
End With
Set pt = Worksheets("MOEVM Summary Level").PivotTables("DeliverPastDue")
Set Field = pt.PivotFields("MOEVM")
NewCat = Worksheets("MOEVM Summary Level").Range("F4").Value
'This updates and refreshes the PIVOT table
With Field
.ClearAllFilters
On Error Resume Next
.CurrentPage = NewCat
End With
Set pt = Worksheets("MOEVM Summary Level").PivotTables("VLQPPastDue")
Set Field = pt.PivotFields("MOEVM")
NewCat = Worksheets("MOEVM Summary Level").Range("F4").Value
'This updates and refreshes the PIVOT table
With Field
.ClearAllFilters
On Error Resume Next
.CurrentPage = NewCat
End With
Set pt = Worksheets("MOEVM Summary Level").PivotTables("Issues")
Set Field = pt.PivotFields("MOEVM")
NewCat = Worksheets("MOEVM Summary Level").Range("F4").Value
'This updates and refreshes the PIVOT table
With Field
.ClearAllFilters
On Error Resume Next
.CurrentPage = NewCat
End With
Set pt = Worksheets("MOEVM Summary Level").PivotTables("IssuesPastDue")
Set Field = pt.PivotFields("MOEVM")
NewCat = Worksheets("MOEVM Summary Level").Range("F4").Value
'This updates and refreshes the PIVOT table
With Field
.ClearAllFilters
On Error Resume Next
.CurrentPage = NewCat
End With
End Sub
Last edited by a moderator: