简体   繁体   English

使用Excel更改数据透视表筛选器

[英]Change Pivot Table Filter Using Excel

I'm developing a solution for some colleagues to use and am trying to automate/simplify as much of it as possible. 我正在开发一种解决方案,以供某些同事使用,并尝试使其尽可能自动化/简化。

My colleagues have a master table of information that is continually added to from external sources by copy/paste. 我的同事有一个主信息表,该信息表通过复制/粘贴从外部来源不断添加。 An example of the table can be found here 该表的示例可以在这里找到

Existing data in the above is example is in black and new data (red) is pasted below it. 上面的示例中的现有数据为黑色,并在其下方粘贴了新数据(红色)。 This table is found on a Worksheet named 'Data' 该表位于名为“数据”的工作表上

The information is then summarised by a Pivot Table named 'Summary' on a separate Worksheet called 'Pivot' and looks like this 然后,在名为“数据透视表”的单独工作表上,通过名为“摘要”的数据透视表对信息进行汇总,如下所示:

I've set up a button for my colleague's to hit which refreshes the Pivot Table with the new data. 我已经设置了一个供同事点击的按钮,该按钮将使用新数据刷新数据透视表。

However, I was looking for a way to change the change the filter of the 'Summary' Pivot Table to only show the information for the most recently added information. 但是,我在寻找一种方法来更改“摘要”数据透视表的筛选器,以仅显示最新添加的信息的信息。 In the example above, it would hide the orders for the 31/04/2018 and show the orders for 01/05/2018. 在上面的示例中,它将隐藏31/04/2018的订单并显示01/05/2018的订单。

I've put together the below but am unsure if it's sensible. 我把下面的内容放在一起,但是不确定是否明智。 Or how I would render all other dates invisible without enumerating them all. 或者,我如何使所有其他日期不可见而又不一一列举。

Any help would be greatly appreciated. 任何帮助将不胜感激。

Thanks 谢谢

Sub PivotUpdate()

Dim CurrDate As Date

Worksheets("Data").Activate
CurrDate = Cells(.Rows.Value, "A").End(xlUp).Row

Workbook.RefreshAll

Worksheets("Pivot").Activate
With ActiveSheet.PivotTables("Summary").PivotFields("Date")
    'Clear all other filter items
    PivotItems(CurrDate).Visible = True
End With

End Sub 结束子

You could use the pretty comprehensive function I posted at Filtering pivot table with vba to do this. 您可以使用我在vba筛选数据透视表中发布的非常全面的功能来执行此操作。 Lots of images at that answer showing the kinds of things it handles, including showing the most recent x days worth of data. 那个答案的许多图像显示了它处理的事情,包括显示最近x天的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM