I can't believe I couldn't find a solution to this on the board...
I created a macro that manipulates data on a worksheet with a pivot table. Now the users want to hide that particular worksheet so it can't be altered (it feeds a graph, so that's the worksheet they want to be "active"). Below is the code I have that works fine, but I can't seem to make the adjustments to make it work when the active sheet is "Status_Graph". I've tried specifying Worksheet("Pivot")., but it errors with the pivot table references. I need to adjust all the references to "Activesheet" so this will run when another worksheet is active. Can someone assist?
I created a macro that manipulates data on a worksheet with a pivot table. Now the users want to hide that particular worksheet so it can't be altered (it feeds a graph, so that's the worksheet they want to be "active"). Below is the code I have that works fine, but I can't seem to make the adjustments to make it work when the active sheet is "Status_Graph". I've tried specifying Worksheet("Pivot")., but it errors with the pivot table references. I need to adjust all the references to "Activesheet" so this will run when another worksheet is active. Can someone assist?
Code:
Sub CopyPivotInfoTesting()
Dim RngPS As Range, RngPCR As Range, Rng As Range
With Sheets("Pivot").PivotTables("PivotTable1")
Columns("A:A").Select
Selection.NumberFormat = "0%"
ActiveSheet.PivotTables("PivotTable1").PivotFields("Offer_to_Target_Pct"). _
AutoSort xlDescending, "Offer_to_Target_Pct"
ActiveSheet.PivotTables("PivotTable1").PivotFields("Offer_to_Target_Pct"). _
PivotItems("(blank)").Position = ActiveSheet.PivotTables("PivotTable1"). _
PivotFields("Offer_to_Target_Pct").PivotItems.Count
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Report_Status")
.PivotItems("Accepted").Visible = True
.PivotItems("No Bid-No Sale").Visible = False
.PivotItems("Rejected").Visible = False
.PivotItems("Pending").Visible = False
With Sheets("Pivot")
Set RngPS = .Range(.Range("A6"), .Range("C" & Rows.Count).End(xlUp))
Set Rng = .Range(.Range("F$2"), .Range("H" & Rows.Count).End(xlUp))
Rng.Resize(, 8).ClearContents
RngPS.Copy .Range("F2")
End With
End With
End Sub