Q:

Unable to run this code as an Macro

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.

A:

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 

