• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Change Pivot Table Selection via Drpdown

Chances are that you had some error generated during code execution. Or code was prematurely terminated.

Add error trap to code.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim strField As String
Dim pvI As PivotItem, pvT As PivotTable
Dim fFlag As Boolean: fFlag = False
Application.EnableEvents = False
Application.ScreenUpdating = False
On Error GoTo ErrHandle:
If Not Intersect(Target, [B6:C6]) Is Nothing Then
    strField = IIf(Target.Address = "$B$6", "Geography", "Product")
    For Each pvT In Sheets("Inno").PivotTables
        With pvT
            For Each pvI In .PivotFields(strField).PivotItems
                If pvI.Value = Target.Value Then
                    .PageFields(strField).CurrentPage = Target.Value
                    fFlag = True
                End If
            Next
            If Not fFlag Then
                .PageFields(strField).CurrentPage = "(All)"
                MsgBox "There is no " & Target.Value & " in current context"
            End If
        End With
    Next
    fFlag = False
End If
ErrHandle:
If Err.Number <> 0 Then
    MsgBox "Something went wrong, comment out error On Error GoTo... and ErrHandle: section of code and step through the code to debug.
End If
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

Ok Thanks. Hopefully this will fix the problem.
 
Back
Top