VBA to EXclude pivotitems in namedrange

dellzy

Board Regular
Joined
Apr 24, 2013
Messages
146
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:
[COLOR=#333333]
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">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>[/COLOR]

Code:
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">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</code>


Appreciate your expertise.

Thank you in advance.

DZ
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try...

Code:
[COLOR=#333333]<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">PI.Visible = (WorksheetFunction.CountIf(Range("cuti"), PI.Name) </code>[/COLOR]<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;"></code><code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">= </code>[COLOR=#333333]<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">0)</code>[/COLOR]

Hope this helps!
 
Upvote 0
WoW! Just one symbol "=" to do that magic! Tqvm Domenic!! Yeayy!

Try...

Code:
[COLOR=#333333]<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">PI.Visible = (WorksheetFunction.CountIf(Range("cuti"), PI.Name) </code>[/COLOR]<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;"></code><code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">= </code>[COLOR=#333333]<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">0)</code>[/COLOR]

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,732
Members
449,093
Latest member
Mnur

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