Pivot Table - Custom Date Filter

sbrotz

Board Regular
Joined
Jul 22, 2004
Messages
138
I am attempting to create a macro that will create a custom date Filter that will mimic the selection of "date filter/after". Below is the code developed from using the macro recorder:

ActiveSheet.PivotTables("Results").PivotFields("Original Date"). _
ClearAllFilters
ActiveSheet.PivotTables("Results").PivotFields("Original Date"). _
PivotFilters.Add Type:=xlAfter, Value1:="10/1/2014"

What I am after is to subsitute the "10/1/2014" date with an entry that will calculate the start date as 60 days prior to todays date. The example below errors - what am I doing wrong?

ActiveSheet.PivotTables("Results").PivotFields("Original Date"). _
ClearAllFilters
ActiveSheet.PivotTables("Results").PivotFields("Original Date"). _
PivotFilters.Add Type:=xlAfter, Value1:="=TODAY()-60"
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I just tested this so I hope it works for you.

I added a variable called Minus

At the head of the macro add:

Dim Minus as Date

Minus = Now() - 60

then change the code on the last line to:
PivotFilters.Add Type:=xlAfter, Value1:=Minus

HTH
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,917
Members
449,093
Latest member
dbomb1414

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