Hello,
I am trying to build a worksheet which enables the user to key in certain data and then apply that data to a pivot table. I have some code to help me accomplish this, but it is not working. It does not apply my data to the pivot table. I have attached my workbook. Any help would be appreciated.
Option Explicit
Sub FilterPivotDates()
'
Dim dStart As Date
Dim dEnd As Date
Dim dname As String
Dim pt As PivotTable
Dim pf As PivotField
Dim pn As PivotField
Dim pi As PivotItem
Application.ScreenUpdating = False
On Error Resume Next
dStart = Sheets("Reports").Range("StartDate").Value
dEnd = Sheets("Reports").Range("EndDate").Value
dname = Sheets("Reports").Range("DataSelection").Value
Set pt = ActiveSheet.PivotTables(1)
Set pf = pt.PivotFields("Date")
Set pn = pt.PivotFields("Name")
pt.ManualUpdate = True
pf.EnableMultiplePageItems = True
pn.EnableMultiplePageItems = True
For Each pi In pf.PivotItems
pi.Visible = True
Next pi
For Each pi In pf.PivotItems
If pi.Value < dStart Or pi.Value > dEnd Then
pi.Visible = False
End If
Next pi
For Each pi In pn.PivotItems
pi.Visible = True
Next pi
Application.ScreenUpdating = False
pt.ManualUpdate = False
Set pn = Nothing
Set pf = Nothing
Set pt = Nothing
End Sub
Thanks
Bookmarks