Filter Pivot Table Using a Date Range

CharlieK86

New Member
Joined
Jun 15, 2016
Messages
1
Hello,

In my Excel worksheet, I have a pivot table which I want to filter by a given date range. The two dates (From & To) are also on the same worksheet but on a different tab.

I have below macro but it doesn't seem to work. Can anyone please help me?

Dim Pt As PivotTable
Dim PeriodField As PivotField
Dim FD As String 'This is From Date
Dim TD As String 'This is To Date


Set Pt = Worksheets("Pivot Tables_ChargeDetail").PivotTables("CD_DOSTable2")
Set PeriodField = Pt.PivotFields("DOS")

FD = Worksheets("Charge Detail_Working").Range("B1").Value
TD = Worksheets("Charge Detail_Working").Range("B2").Value

With Pt
.PeriodField.ClearAllFilters
With.PeriodField
.PivotFilters.Add Type:=xlDateBetween, Value1:=FD, Value2:=TD
End With
End With
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,216,403
Messages
6,130,364
Members
449,576
Latest member
DrSKA

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top