滤除数据透视表中的奇数

在我的数据透视表的源表中; 包含两列; 一个是名字 ,另一个是分数 。 正如主题标题所暗示的那样,我想要显示偶数分数的所有名称及其相应的分数。

另一种方法是创build第三列,并运行IF公式来检查哪些数字是奇数。 然后将第三列包括到数据透视表中,并将其用作filter。

但有没有办法做到这一点,而不修改源?

你可以循环通过枢轴项目,然后将它们除以2以检查它们是否是偶数,如果它们不是,那么只是隐藏它们。 看到这个例子。 请修改它以适应您的需求。 另外,我还没有做任何error handling。 我相信你可以照顾那个…

Option Explicit Sub HideOddNumbers() Dim ws As Worksheet Dim pvtItem As PivotItem Dim pvt As PivotTable Dim pvtFld As PivotField '~~> Change this to the respective sheet Set ws = ThisWorkbook.Sheets("Sheet1") '~~> Change this to the respective pivot name Set pvt = ws.PivotTables("PivotTable1") '~~> This is the column Set pvtFld = pvt.PivotFields("Scores") With pvtFld .CurrentPage = "(All)" .EnableMultiplePageItems = True '~~> Loop through all items in the pivot and '~~> divide the values by 2 and check if they are even or not For Each pvtItem In pvtFld.PivotItems If Val(pvtItem.Value) Mod 2 <> 0 Then pvtItem.Visible = False Next End With End Sub 

屏幕截图

之前

在这里输入图像描述

之后

在这里输入图像描述