I've been looking for an answer before, many topics similar but not the same are existing, and I couldn't find an answer to my issues.
I have a macro allowing me to change the filter of a PVT automatically, and refreshing the PVT. The filter is changed accordingly to the value of a cell (copy / paste of the value of the cell in the PVT filter)
Lately, every since I add some more data into the table related to the Pivot Table, I cannot run the macro anymore otherwise
"Microsoft Excel has stopped working".
The VBA code is still the same, nothing elsa hsa changed so I don't really understand.
Please find after the code:
Sub update_Filter()
Application.ScreenUpdating = False
ActiveSheet.Calculate
'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim NewFilter As String
'Here you amend to suit your data
Set pt = Worksheets("PVT Competition Data").PivotTables("PivotTable3")
Set Field = pt.PivotFields("PN ******")
NewFilter = Worksheets("PVT Competition Data").Range("B4").Value
On Error Resume Next
'This updates and refreshes the PIVOT table
With pt
Field.ClearAllFilters
Field.CurrentPage = NewFilter
pt.RefreshTable
Range("E12:I12").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("E12").Select
End With
End Sub
If you find something wrong to this or if you have any explanations, you will save my day (and for sure the followings...).
Also please ask if you need more details.
Thanks in advance!