'Pivot filter for month
'''
Dim SheetName As String
Dim PivotName As String
Dim FieldName As String
Dim Filter As String
Dim PI As PivotItem
SheetName = ActiveSheet.Name
PivotName = "PivotTable1"
FieldName = "MONTH"
Filter = ActiveSheet.Range("C1")
Worksheets(SheetName).PivotTables("PivotTable1").ManualUpdate = True
With ThisWorkbook.Worksheets(SheetName).PivotTables(PivotName).PivotFields(FieldName)
.ClearAllFilters
.EnableMultiplePageItems = False
For Each PI In .PivotItems
If PI.Name = Filter Then
PI.Visible = True
Else: PI.Visible = False
End If
Next
End With
我正在使用此代码将我的数据透视表过滤到单元格C1中显示的数字。这段代码为我提供了过滤到我想要的值的数据透视表,但它有"选择多个项目" (由于某种原因,所有值都是空白的)框已选中,我需要取消选中此项,然后将数据透视表过滤为" C1"中显示的值。
任何帮助都将不胜感激。