I have been trying to automate this macro that's filtering the date range depending on the input date field(I have given the input date as July 2022). This date range filter should be applied in such a way that it should include three years before the input year(i.e. 2020-2022) and all the months before the input month(jan-july).
I'm not sure how to create a generalized for loop for the filter below that will automatically change the year and month according to the input field. I have tried to create a for loop for just the month for the current year but don't know how to combine the ranges for the previous three years as well.
Sub Macro2()
'
' Macro2 Macro
'
'
ActiveSheet.PivotTables("NetRate22").PivotFields( _
"[Policy State Dimensions].[Effective Date].[Effective Year]"). _
VisibleItemsList = Array("")
ActiveSheet.PivotTables("NetRate22").PivotFields( _
"[Policy State Dimensions].[Effective Date].[Effective Month]"). _
VisibleItemsList = Array( _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2020]&[1]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2020]&[2]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2020]&[3]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2020]&[4]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2020]&[5]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2020]&[6]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2020]&[7]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2021]&[1]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2021]&[2]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2021]&[3]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2021]&[4]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2021]&[5]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2021]&[6]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2021]&[7]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2022]&[1]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2022]&[2]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2022]&[3]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2022]&[4]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2022]&[5]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2022]&[6]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2022]&[7]")
ActiveSheet.PivotTables("NetRate22").PivotFields( _
"[Policy State Dimensions].[Effective Date].[Effective Day]").VisibleItemsList _
= Array("")
End Sub
I have been trying to solve this for a month now and haven't found the best resources in VBA to help with this solution.
Any help with this problem is appreciated. Thanks!
I'm not sure how to create a generalized for loop for the filter below that will automatically change the year and month according to the input field. I have tried to create a for loop for just the month for the current year but don't know how to combine the ranges for the previous three years as well.
Sub Macro2()
'
' Macro2 Macro
'
'
ActiveSheet.PivotTables("NetRate22").PivotFields( _
"[Policy State Dimensions].[Effective Date].[Effective Year]"). _
VisibleItemsList = Array("")
ActiveSheet.PivotTables("NetRate22").PivotFields( _
"[Policy State Dimensions].[Effective Date].[Effective Month]"). _
VisibleItemsList = Array( _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2020]&[1]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2020]&[2]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2020]&[3]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2020]&[4]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2020]&[5]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2020]&[6]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2020]&[7]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2021]&[1]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2021]&[2]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2021]&[3]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2021]&[4]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2021]&[5]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2021]&[6]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2021]&[7]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2022]&[1]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2022]&[2]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2022]&[3]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2022]&[4]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2022]&[5]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2022]&[6]", _
"[Policy State Dimensions].[Effective Date].[Effective Month].&[2022]&[7]")
ActiveSheet.PivotTables("NetRate22").PivotFields( _
"[Policy State Dimensions].[Effective Date].[Effective Day]").VisibleItemsList _
= Array("")
End Sub
I have been trying to solve this for a month now and haven't found the best resources in VBA to help with this solution.
Any help with this problem is appreciated. Thanks!