无法以宏的形式运行此代码

时间:2022-11-01 20:23:11

Any idea why I'm unable to run this code as an Macro?

你知道为什么我不能用宏运行这段代码吗?

Sub PivotFilter()

Application.ScreenUpdating = False

Dim PI As PivotItem

With Worksheets("Sheet2").PivotTables("PivotTable2").PivotFields("OrgUnit Code:")
    .ClearAllFilters

    'Refreshing pivot table seems to remove the "set visible property" error
    Worksheets("Sheet2").PivotTables("PivotTable2").RefreshTable

For Each PI In .PivotItems
    PI.Visible = WorksheetFunction.CountIf(Range("b:b"), PI.Name) > 0
Next PI

End With

    Worksheets("Sheet2").PivotTables("PivotTable1").RefreshTable

End Sub

Any idea what the reason for this may be?

你知道原因是什么吗?

Many thanks in advance.

提前感谢。

1 个解决方案

#1


1  

Try making it public

试着让它公开

Public Sub PivotFilter()
     '...
End Sub

Excel sometimes can't/don't want to run private subs when running with the play button or pressing f5

当使用play按钮或按f5运行时,Excel有时不能/不希望运行私有子。

#1


1  

Try making it public

试着让它公开

Public Sub PivotFilter()
     '...
End Sub

Excel sometimes can't/don't want to run private subs when running with the play button or pressing f5

当使用play按钮或按f5运行时,Excel有时不能/不希望运行私有子。