• 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.

Refreshing Pivot Table on a Protected Sheet

Matt F

New Member
Hello,

I have a workbook with a data table and pivot table on a protected worksheet.

I would like the user to refresh the content in the pivot table when then unhide the pivot table content.

Can someone help with this Macro?

Code:
Sub show_hide()

ActiveSheet.Unprotect Password:="mypassword"

If Range("table_all_range").EntireRow.Hidden = True Then
Range("table_all_range").EntireRow.Hidden = False
  Else
Range("table_all_range").EntireRow.Hidden = True
End If

ActiveSheet.Protect Password:="mypassword"


End Sub
 

Attachments

  • Pivot Refresh and Protect.xlsm
    22.9 KB · Views: 3
How's this look?
Code:
Sub show_hide()
Const MyPass = "mypassword"

ActiveSheet.Unprotect MyPass
With Range("table_all_range").EntireRow
    'Change to a toggle
    .Hidden = Not .Hidden
End With
'Refreshes the 1st PivotTable in our sheet
'In this workbook, there's only 1. Otherwise, can specify the name like
'ActiveSheet.PivotTables("PivotTable6").PivotCache.Refresh
ActiveSheet.PivotTables(1).PivotCache.Refresh

ActiveSheet.Protect Password:=MyPass

End Sub
 
Back
Top