Hello all,
I'm working on a report that uses a pivot table to display multiple years of daily data for several product prices.
I need to be able to control the report filter to display several different months based on the value of a specific cell. Here is the VBA I have so far.
This code only sorts based on the single value in cell K2. I'd appreciate any and all help.
Thank you!
I'm working on a report that uses a pivot table to display multiple years of daily data for several product prices.
I need to be able to control the report filter to display several different months based on the value of a specific cell. Here is the VBA I have so far.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("k2:k3")) Is Nothing Then Exit Sub
Dim pt As PivotTable
Dim Field As PivotField
Dim ThisMonth As String
Set pt = Worksheets("Sheet4").PivotTables("PivotTable1")
Set Field = pt.PivotFields("Column1")
ThisMonth = Worksheets("Sheet4").Range("k2").Value
With pt
Field.ClearAllFilters
Field.CurrentPage = ThisMonth
pt.RefreshTable
End With
End Sub
This code only sorts based on the single value in cell K2. I'd appreciate any and all help.
Thank you!