数据透视更改滤镜的宏无效

时间:2019-09-10 14:16:00

标签: excel vba

社区,除了宏最初什么都不做的事实之外,这里需要您的帮助,我现在遇到错误1004:应用程序或对象定义的错误! 我更新了查询以简化并希望更正宏的无效结果,但是现在我使情况更糟了。请提供任何帮助

Sub changeFilters()

Dim wsChart As Worksheet: Set wsChart = Sheets("Graph Data")
Dim wsPivot As Worksheet: Set wsPivot = Sheets("PCW_pivot")
Dim pt As PivotTable: Set pt = wsPivot.PivotTables("PCW1")
Dim pf As PivotField: Set pf = pt.PivotFields("[Range].[Geography].[Geography]")
Dim SelGeo As Variant: SelGeo = Sheets("Graph Data").Range("E3").Value

'turn on automatic update / calculation in the Pivot Table

With SelGeo <> "WW"
    pt.ManualUpdate = True
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    pf.PivotFilters.Add Type:=xlCaptionEquals, Value1:="[SelGeo]"
    pt.RefreshTable
    End With
With SelGeo = "WW"
.ClearAllFilters
  End With
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub

0 个答案:

没有答案