excel 滤镜实时刷新

excel real time refresh of filter

在 excel 中的数据透视表 Table 中,我有一个关于某些报告的截止日期的字段列表。

例如,2016 年 10 月 5 日

我的问题是,每天我都必须选择日期才能看到报告代码,我不希望它是这样的。我想要的是,每天我打开 excel,过滤器会自动从 10/5/2016 更改为 11/5/2016.

我应该使用什么功能/VBA?

有帮助

如果您想要 VBA 解决方案,请将以下内容添加到 ThisWorkbook 代码中。

Private Sub Workbook_Open()

Dim tDay As Date, pf As PivotField
tDay = Date

    Set pf = Sheets("name of worksheet").PivotTables("pivot table name").PivotFields("insert the name of your filter here")

    pf.ClearAllFilters
    pf.CurrentPage = tDay

End Sub

更改 sheet 名称、枢轴 table 名称和过滤器名称。

如果您需要对枢轴 table 进行更多 VBA 操作,我建议阅读以下内容 http://www.thespreadsheetguru.com/blog/2014/9/27/vba-guide-excel-pivot-tables