Hi all, I've been trying to fix this one myself with a little research and trial and error, but I've drawn a blank.
I inherited some VBA that used to unprotect a worksheet, refresh some pivot tables, got to the pivot table in the current sheet, colour a range (to show that the worksheet was locked), and then re-protect the worksheet. The is repeated in different subs to refresh and display different pivot tables, eight in all. The workbook has multiple worksheets, each worksheet identical in design but displaying different data.
At least that's what it did before we upgraded our Excel version a couple of weeks ago.
Now the code does everything it did before, but instead of showing the pivot table on the current sheet, it jumps to the same pivot table on a different worksheet.
I assume the current worksheet is no longer the active worksheet. But I'm afraid my knowledge is limited.
Code is as follows.
Many thanks for any help or advice you could possibly provide.
I inherited some VBA that used to unprotect a worksheet, refresh some pivot tables, got to the pivot table in the current sheet, colour a range (to show that the worksheet was locked), and then re-protect the worksheet. The is repeated in different subs to refresh and display different pivot tables, eight in all. The workbook has multiple worksheets, each worksheet identical in design but displaying different data.
At least that's what it did before we upgraded our Excel version a couple of weeks ago.
Now the code does everything it did before, but instead of showing the pivot table on the current sheet, it jumps to the same pivot table on a different worksheet.
I assume the current worksheet is no longer the active worksheet. But I'm afraid my knowledge is limited.
Code is as follows.
Code:
Sub Trans()
Application.ScreenUpdating = False
Dim ws As Worksheet
Dim pt As PivotTable
Dim ptCache As PivotCache
Dim Pwd As String
For Each ws In Worksheets
ws.Unprotect Password:="password"
Next ws
With ActiveSheet
For Each pt In .PivotTables
pt.RefreshTable
Set pt = ActiveSheet.PivotTables("Pivot1")
For Each PivotItem In pt.PivotFields("Transition").PivotItems
If PivotItem.Value = "(blank)" Then PivotItem.Visible = False
Next PivotItem
Next pt
End With
Application.ScreenUpdating = True
ActiveWorkbook.ShowPivotTableFieldList = False
Range("M12435").Select
Range("J7:K11").Interior.ColorIndex = 3
For Each ws In Worksheets
ws.Protect Password:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True, _
AllowDeletingRows:=True, AllowInsertingRows:=True, AllowFiltering:=True, AllowUsingPivotTables:=True
Next ws
End Sub
Many thanks for any help or advice you could possibly provide.