VBA script to Filter Pivot Table Dates

EaZyCheaZ

New Member
Joined
May 10, 2010
Messages
5
I am trying to come up with a way to fitler a pivot table by date the same way i can with the filter dropdown. I have a table that filters using the TODAY feature in the filter dropdown undet date filters. I would like to assign a vba to a pair of buttons for easy switching between the "Today" date filter and the "Yesterday" feature so i no longer have to pull it up from teh filter dropdown.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Sub LastMonth()
Dim pt As PivotTable
Dim ptF As PivotField

Application.ScreenUpdating = False

Set pt = ActiveSheet.PivotTables("TABLENAME")
With pt
.ManualUpdate = True
.PivotCache.Refresh
For Each ptF In .PivotFields
If ptF.DataType = xlDate And ptF.Orientation <> xlHidden Then
With ptF
.ClearAllFilters
.PivotFilters.Add Type:=xlDateLastMonth
End With
End If
Next ptF
.ManualUpdate = False
End With

Application.ScreenUpdating = True
End Sub

Thanks to all who viewed but i found my own answer...oh well...i'll still come here for other answers but i doubt i'm posting again
 
Upvote 0

Forum statistics

Threads
1,214,874
Messages
6,122,034
Members
449,061
Latest member
TheRealJoaquin

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