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.
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.
Above is the format i'm trying to apply.
Thanks in advance!
Swiemel
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