Trying to updated pivot table filters of different sheets of different workbook, but the getting error message "Run-time error '-2147024809(80070057)' - The PivotTable field name is not valid... "
Need help to resolve the issue and get the code running.
Need help to resolve the issue and get the code running.
Code:
Private Function UPivot(PName As String, FilePath As String, colcount As Long, rangecount As Long) As String
' pivot table assignment filter
ActiveSheet.PivotTables(PName).ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
FilePath & "!R1C1:R" & rangecount + 1 & "C" & colcount _
, Version:=xlPivotTableVersion15)
With ActiveSheet.PivotTables(PName).PivotFields("Has breached")
.PivotItems("(blank)").Visible = False
End With
ActiveWorkbook.RefreshAll
ActiveSheet.PivotTables(PName).PivotFields("Assignment group"). _
CurrentPage = "(All)"
'START - To unselect all Pivot Items except Blank
Set pf = Worksheets("SUMMARY").PivotTables(PName).PivotFields("Assignment group")
pf.ClearAllFilters
For i = 1 To pf.PivotItems.Count
If pf.PivotItems(i) <> "(blank)" Then
pf.PivotItems(i).Visible = False
End If
Next
'END OF - To unselect all Pivot Items except Blank
With ActiveSheet.PivotTables(PName).PivotFields("Parent2")
.PivotItems("External User Region").Visible = False
End With
End Function
Last edited by a moderator: