Date Filter via Code?

UpTheArgyle

Board Regular
Joined
Jan 12, 2006
Messages
179
Hi
I have a pivot table I use daily - within the pivot I use date filter Between 2 dates.

The 2 dates I use are always in 2 separate cells on the same sheet.

Is it possible some code to pick the 2 dates up from the sheet?

Recording a macro (below) I get this but obviously the date are the dates I manually enter.

ActiveSheet.PivotTables("PivotTable5").PivotFields("calendar_date"). _
PivotFilters.Add Type:=xlDateBetween, Value1:="01/04/2011", Value2:= _
"24/06/2011"

Thanks
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try like this - change A1 and A2 to suit

Code:
ActiveSheet.PivotTables("PivotTable5").PivotFields("calendar_date"). _
PivotFilters.Add Type:=xlDateBetween, Value1:=Range("A1").Value, Value2:=Range("A2").Value
 
Upvote 0
good God, not Plymouth Argyle I hope...

name two cells Date1 and Date2, or whatever else you want

ActiveSheet.PivotTables("PivotTable5").PivotFields("calendar_date"). _
PivotFilters.Add Type:=xlDateBetween, Value1:=Range("Date1"), Value2:= Range("Date2")
 
Upvote 0
whats green and white and slides down the table.............yes its Plymouth Argyle !!

Thanks for the replies gents
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,134
Members
452,890
Latest member
Nikhil Ramesh

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