+ Reply to Thread
Results 1 to 2 of 2

Pivot Filter based off drop down cell will not update in protected sheet

  1. #1
    Registered User
    Join Date
    05-30-2014
    Posts
    2

    Pivot Filter based off drop down cell will not update in protected sheet

    I have a sheet that contains several pivot tables, with charts running off of them. A drop down menu changes one of the filters in the pivot tables. Everything works just fine, but when I protect the sheet, the drop down cell does not affect the pivot filter. Here is my code (to include some trouble shooting code to see if I could get it to work):

    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim ws As Worksheet
    Dim pt As PivotTable
    Dim pi As PivotItem
    Dim strField As String
    Dim strField2 As String
    Dim strField4 As String

    strField = "QUARTER"
    strField2 = "FY"
    strField4 = "TFM"

    On Error Resume Next
    Application.EnableEvents = False
    Application.ScreenUpdating = False



    If Target.Address = Range("ProductSelect").Address Then

    ' For Each ws In ThisWorkbook.Worksheets
    Set ws = Me
    ws.Unprotect
    AllowUsingPivotTables = True
    For Each pt In ws.PivotTables
    With pt.PageFields(strField4)
    For Each pi In .PivotItems
    If pi.Value = Target.Value Then
    .CurrentPage = Target.Value
    Exit For
    Else
    .CurrentPage = "(All)"
    End If
    Next pi
    End With
    Next pt
    ws.Protect
    ' Next ws

    End If

    If Target.Address = Range("QtrSelect").Address Then

    ' For Each ws In ThisWorkbook.Worksheets
    Set ws = Me
    ws.Unprotect
    AllowUsingPivotTables = True
    For Each pt In ws.PivotTables
    With pt.PageFields(strField)
    For Each pi In .PivotItems
    If pi.Value = Target.Value Then
    .CurrentPage = Target.Value
    Exit For
    Else
    .CurrentPage = "(All)"
    End If
    Next pi
    End With
    Next pt
    ws.Protect
    ' Next ws

    End If

    If Target.Address = Range("FYSelect").Address Then

    ' For Each ws In ThisWorkbook.Worksheets
    Set ws = Me
    ws.Unprotect
    AllowUsingPivotTables = True
    For Each pt In ws.PivotTables
    With pt.PageFields(strField2)
    For Each pi In .PivotItems
    If pi.Value = Target.Value Then
    .CurrentPage = Target.Value
    Exit For
    Else
    .CurrentPage = "(All)"
    End If
    Next pi
    End With
    Next pt
    ws.Protect
    ' Next ws

    End If

    ws.Protect

    Application.EnableEvents = True
    Application.ScreenUpdating = True

    End Sub

    Please help...

  2. #2
    Registered User
    Join Date
    05-30-2014
    Posts
    2

    Re: Pivot Filter based off drop down cell will not update in protected sheet

    Here is my updated code. Everything works until I protect the sheet, then when I select the drop down, the pivots do not update.



    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim ws As Worksheet
    Dim pt As PivotTable
    Dim pi As PivotItem
    Dim strField As String
    Dim strField1 As String
    Dim strField3 As String

    strField = "FY"
    strField1 = "QUARTER"
    strField3 = "TFM"

    On Error Resume Next
    Application.EnableEvents = False
    Application.ScreenUpdating = False



    If Target.Address = Range("QtrSelect").Address Then

    ' For Each ws In ThisWorkbook.Worksheets
    Set ws = Me
    For Each pt In ws.PivotTables
    With pt.PageFields(strField1)
    For Each pi In .PivotItems
    If pi.Value = Target.Value Then
    .CurrentPage = Target.Value
    Exit For
    Else
    .CurrentPage = "(All)"
    End If
    Next pi
    End With
    Next pt
    ' Next ws

    Else

    If Target.Address = Range("ProductSelect").Address Then

    ' For Each ws In ThisWorkbook.Worksheets
    Set ws = Me
    For Each pt In ws.PivotTables
    With pt.PageFields(strField3)
    For Each pi In .PivotItems
    If pi.Value = Target.Value Then
    .CurrentPage = Target.Value
    Exit For
    Else
    .CurrentPage = "(All)"
    End If
    Next pi
    End With
    Next pt
    ' Next ws

    Else

    If Target.Address = Range("FYSelect").Address Then

    ' For Each ws In ThisWorkbook.Worksheets
    Set ws = Me
    For Each pt In ws.PivotTables
    With pt.PageFields(strField)
    For Each pi In .PivotItems
    If pi.Value = Target.Value Then
    .CurrentPage = Target.Value
    Exit For
    Else
    .CurrentPage = "(All)"
    End If
    Next pi
    End With
    Next pt
    ' Next ws

    End If

    End If

    End If

    Application.EnableEvents = True
    Application.ScreenUpdating = True

    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Update pivot tables based on source data filter
    By papasmurfuo9 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-26-2014, 08:03 AM
  2. Update a pivot filter based on cell value by using a button
    By tray262 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 08-23-2013, 02:40 PM
  3. Update Pivot Report Filter Value based on cell updated by formula
    By carlwin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-01-2013, 08:28 AM
  4. Update All Pivot in sheet based on 1 filter
    By piyush85 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-29-2011, 03:26 PM
  5. Replies: 0
    Last Post: 05-24-2011, 09:53 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1