Count Number of Selected PivotTable Filters

JWilley88

New Member
Joined
Jun 17, 2016
Messages
4
Good afternoon folks!

I have another tough question.

I have a PivotTable Report Filter that I want to Count the amount of selections in that filter preferably via VBA but a formula would work ok too.

So for a Person's Name, there's a filter under it for Dates and I'd like to be able to count the amount of Dates selected
Ex. I select Jan, Feb, Mar to filter the data by, the Count returns a value of 3


This is sort of what I want but it isn't working:

Sub DateCount()


MsgBox Worksheets("Sheet1").PivotTables("Name").PivotFields("Dates").PivotItems.Count


End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Try...

Code:
[color=darkblue]Sub[/color] DateCount()

    [color=darkblue]Dim[/color] oPivotItem [color=darkblue]As[/color] PivotItem
    [color=darkblue]Dim[/color] lCnt [color=darkblue]As[/color] [color=darkblue]Integer[/color]

    lCnt = 0
    [color=darkblue]For[/color] [color=darkblue]Each[/color] oPivotItem [color=darkblue]In[/color] Worksheets("Sheet1").PivotTables("Name").PivotFields("Dates").PivotItems
        [color=darkblue]If[/color] oPivotItem.Visible [color=darkblue]Then[/color]
            lCnt = lCnt + 1
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]Next[/color] oPivotItem
    
    MsgBox lCnt

[color=darkblue]End[/color] [color=darkblue]Sub[/color]

Hope this helps!
 
Upvote 0
Have you tried this?

Set it up as slicer and then use: (maybe you don't need to make it as a slicer.

=+CUBESETCOUNT(Slicer_Month)
 
Upvote 0

Forum statistics

Threads
1,223,719
Messages
6,174,089
Members
452,542
Latest member
Bricklin

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