Got some great code help from someone here yesterday and it worked fine. The code works great the first time I run it. But if I try to make a different selection in the drop down, it errors out (Error 1004 unable to set the visible property of the pivot item class)

If I close the workbook without saving and reopen, it will work one time.


Sub SomePivots()
'---------------------------------------------------------------------------------------
' Procedure : SameSelection
' Date      : 2/1/2012
' Purpose   : Updates all Pivots in array of worksheets
'---------------------------------------------------------------------------------------

Dim P As PivotTable
    Application.ScreenUpdating = False
    Dim sh As Worksheet
For Each sh In Worksheets(Array("XXXX"))
    For Each P In sh.PivotTables
        With P.PivotFields("XXXX")

        'Show all pivotitems
        For IndexCtr = 1 To .PivotItems.Count
            .PivotItems(IndexCtr).Visible = True
        Next IndexCtr

        'Display only what's in cell I1
        On Error GoTo BadNews
        For i = 1 To .PivotItems.Count
            If .PivotItems(i).Name Like Sheets("XXXX").Range("V6").Value Then
                .PivotItems(i).Visible = True
            Else
                .PivotItems(i).Visible = False
            End If
        Next i
    End With
    Next
    Next
    Application.ScreenUpdating = True
    Exit Sub
BadNews:
    Application.ScreenUpdating = True
    MsgBox "XXXX not found this month. There may be no XXXX associated with this XXXX. If you feel you have reached this message in error, email XXXX@XXX.com"
    Exit Sub

End Sub