Hi,
I am trying to filter a pivot table using VBA. Specifically a date range. So I want a user to enter a date from and to on a excel sheet and the pivot will then update based on them cells, however I have been unable to thus far.
I have attached an example of my problem.
What I have been able to do so far is filter by 'date' when it is added in as a 'row label' by:
Sub UpdatePivot()
Dim PvtTbl As PivotTable
Set PvtTbl = Worksheets("Worksheet").PivotTables("PivotTable1")
PvtTbl.ClearAllFilters
PvtTbl.PivotFields("Date").PivotFilters.Add Type:=xlDateBetween, Value1:=CLng(Range("Datefrom").Value), Value2:=CLng(Range("Dateto").Value)
End Sub
-This doesn't work when I have 'date' just in my filter and not row label, as I do not want to do this.
-Please could someone help, I've been trying for a while to fix this now.ExampleofPivot.xlsx
Bookmarks