Set the date filter on yesterday on opening of pivot table

Shamimo

New Member
Joined
Jul 4, 2011
Messages
7
Hi,

I have a pivot table linked to a warehouse that displays sales Values.

I would like that on opening of the pivot table, the date filter for the report is automatically set to yesterday's date instead of displaying the last saved date.

I have never used a VBA code and tried to do it with an inserted calculated fields but with no avail.

Can someone help me please ?

Thanks a lot for taking the time.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
You can create a macro that runs automatically whenever the file is opened, as long as macros are enabled.
All that is needed is to name the macro as "Auto_Open".

This code appears to do what you want . . . .
Code:
Sub Auto_Open()
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Date").PivotFilters.Add _
        Type:=xlDateYesterday
    
End Sub
 
Upvote 0
All that is needed is to name the macro as "Auto_Open".

Nifty. Adds flexibility over "Private Sub Workbook_Open()"

Thanks for sharing!

tonyyy
 
Upvote 0

Forum statistics

Threads
1,216,116
Messages
6,128,933
Members
449,480
Latest member
yesitisasport

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