• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA to EXclude pivotitems in named range

Dahlia

Member
Hello Excel Experts,

I found several amazing macros from amazing excel experts to filter pivotitems, but it covers to INCLUDE pivotitems in namedrange or after minor change, I can get to EXCLUDE pivotitem but only 1 item or multiple items if I hardcode them all as fixed in VBA. However, what I really need is for it to be able to filter out by namedrange because the input may change from time to time because the input is holidays dates throughout the year.
Below are my findings so far. Perhaps someone expert can tweak some lines to meet my objective:-

Code:
Sub TestINclude()
Dim PI As PivotItem
With Worksheets("Sheet2").PivotTables("PivotKPI").PivotFields("AssignDt")
.ClearAllFilters
For Each PI In .PivotItems
PI.Visible = WorksheetFunction.CountIf(Range("cuti"), PI.Name) > 0
Next PI
End With
End Sub

Code:
Sub TestEXclude()
Dim PI As PivotItem
With Worksheets("Sheet2").PivotTables("PivotKPI").PivotFields("AssignDt")
.ClearAllFilters
'For Each PI In .PivotItems
' PI.Visible = WorksheetFunction.CountIf(Range("cuti"), PI.Name) > 0
'Next PI
.PivotItems(Range("cuti")).Visible = False
End With
End Sub

Appreciate your expertise.

Thank you in advance.

DZ
 
Back
Top