Filtering Pivottables to show data that is equal of before target date

Swiemel

New Member
Joined
Jun 18, 2015
Messages
12
Hi everyone,

I'm using vba to filter a series of Pivottables on different worksheets within the same workbook. Most of these Pt's don't really form a problem. However for my reports i want to be able to set the YTD months (in reportfilter) to the same month i'm defining in NewCat 1, 2 or 3.

Code:
  Dim pt As PivotTable            
            Dim Field1 As PivotField
            Dim NewCat1 As String '<- Current Month (mm)
            Dim NewCat2 As String '<- Current Month (mm_2015)
            Dim NewCat3 As Date  '<- Reference date end of month (dd_mm_yyyy)
                                     
            NewCat1 = Worksheets("LinkFile Stuurinfo").Range("B55").Value
            NewCat2 = Worksheets("LinkFile Stuurinfo").Range("C55").Value
            NewCat3 = Worksheets("LinkFile Stuurinfo").Range("E55").Value
            NewCat4 = Worksheets("LinkFile Stuurinfo").Range("D55").Value

Code:
 Set pt = Worksheets("Rev_Binnen").PivotTables("Rev_Binnen_ytd")           
           Set Field1 = pt.PivotFields("Maand")
            
            For Each pvtitm In pt.PivotFields("Maand").PivotItems
            If pvtitm.Value <= NewCat2 Then
            pvtitm.Visible = True
            Else
            pvtitm.Visible = False
                         
            End If
                        
            Next

This works fine for NewCat2 (it selects 01_2015 to 10_2015) but not for NewCat 1 or 3??

Does anyone have an idea on how to make this work for the other variable?
When i amend this code for NewCat 1 (currently set on '10') it only selects months 1 and 10 instead of 1 to 10.

Code:
           Set pt = Worksheets("Rev_Afgehandeld").PivotTables("Rev_Afgehandeld_ytd")
           Set Field1 = pt.PivotFields("Peildatum Def")
            
            For Each pvtitm In pt.PivotFields("Peildatum Def").PivotItems
            If pvtitm.Value <= NewCat3 Then
            pvtitm.Visible = True
            Else
            pvtitm.Visible = False
                         
            End If
                        
            Next

Above is the format i'm trying to apply.

Thanks in advance!

Swiemel
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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