Use VBA to Update PivotTable Items?

foolishpiano

New Member
Joined
Aug 19, 2016
Messages
25
Hello everyone! I have a macro that tracks the history of items submitted to our system the previous day. This macro saves the data in a table, and I summarize the data with a PivotTable. Management is only interested in items submitted from 3/16 forward, so my PivotTable is filtered to show items submitted 3/16 forward. Everyday I have to add yesterday's date to the filter manually, and I'm just wondering if there is a way to do this through VBA? I tried recording a macro today to see what Excel is doing, and what was recorded was:
VBA Code:
    With ActiveSheet.PivotTables("PivotTable2").PivotFields("CompSubmit")
        .PivotItems("4/16/2020").Visible = True

What I'm hoping is that I could change the PivotItems field from a hardcoded field to dynamically updating to yesterday's date. Would something like this be possible? I was thinking of referring to a range with yesterday's date in it, such as having cell AI1 = Today()-1, or having the calculation in the VBA code itself; I'm just not sure how it would work.

Any help would be greatly appreciated!

Thanks for reading my post and for your suggestions!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,214,808
Messages
6,121,684
Members
449,048
Latest member
81jamesacct

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