Excel VBA使用CurrentPage

时间:2016-05-10 03:32:04

标签: excel vba excel-vba

我这里有代码

 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

它每次都可以更新过滤器列表,但是我希望它在过滤器列表中单击2个项目呢?

1 个答案:

答案 0 :(得分:1)

在您的情况下,“tDay”将是第一个过滤值。您可以在昏迷后添加更多项目。

Sub SamplePivotUpdate()
Dim PI As PivotItem
With ActiveSheet.PivotTables("your pivot name").PivotFields("your field name")
.ClearAllFilters
For Each PI In .PivotItems
Select Case PI
    Case "1 value to filter", "2 value to filter": PI.Visible = True
    Case Else: PI.Visible = False
End Select
Next PI
End With
End Sub