Hi,
This is my first post, although I have spent a great deal of time browsing other posts for solutions to my problems. I have learned a lot.
On a sheet called, "Details", I have a pivot table that has three fields in the column area, Calendar type, Description, and Dates.
I want to filter the pivot table based on a label filter in the Dates column. The filter should be between two dates (in D4 and D5) that are entered on another sheet and passed to the Details sheet through formulas in cells D4 and D5.
I have attached the following code to a button on a different sheet.
The code successfully filters for the employee name (which is a report filter in the pivot table) which is in a named cell.
I am having trouble with passing the start and end dates to my pivot table filter.
I do not get any errors, the filter is simply blank.
Any insight would be appreciated.
Private Sub CommandButton3_Click()
Sheets("Details").Select
Dim pt As PivotTable
Dim Employee As String
Dim SDate As String
Dim EDate As String
Set pt = Worksheets("Details").PivotTables("PivotTable1")
Employee = Range("EmpName").Value
SDate = Range("D4")
EDate = Range("D5")
pt.ClearAllFilters
pt.PivotFields("Employee Name").CurrentPage = Employee
pt.PivotFields("Dates").PivotFilters.Add Type:=xlCaptionIsBetween, Value1:=SDate, Value2:=EDate
End Sub
Bookmarks