L
Lee
Below is a sample of a pivot table that I'm trying to restrict. Found code
on the web that allows me to do it but I'm having a problem
Sub h_PT_Restrict_PivotTable()
'Restrict pivot table functionality
Dim pf As PivotField
With ActiveSheet.PivotTables(1)
.EnableWizard = False
.EnableDrilldown = False
.EnableFieldList = False 'Excel 2002+
.EnableFieldDialog = False
.PivotCache.EnableRefresh = False
For Each pf In .PivotFields
'If pf.Value = "Data" Then End
With pf
.DragToPage = False
.DragToRow = False
.DragToColumn = False
.DragToData = False
.DragToHide = False
End With
Next pf
End With
End Sub
This works fine until it hits "Data". I can put a watch on it and see it
run through all of the pivot fields. It will run through each field coming
to "Data" last. When the pf value becomes "Data" the macro stops on
..DragToPage = False with an application defined or object defined error.
Any ideas ? I put an If statement (commented out above) that when the pf
value = "Data" then end. This works fine as long as the user doesn't change
"Data" to anything else, if they do then it's back to the same problem.
Should it read "Data" as a pivot field?
Data
TASK ID DESCRIPTION Labor Cost Other Cost
1.1 Base Year Labor $ 131,596 $ 9,527
2.1 Option Period 1 Labor $ 542,806 $ 39,296
3.1 Option Period 2 Labor $ 575,364 $ 41,653
4.1 Option Period 3 Labor $ 610,398 $ 44,189
5.1 Option Period 4 Lalbor $ 647,571 $ 46,880
Grand Total $2,507,735 $ 181,545
on the web that allows me to do it but I'm having a problem
Sub h_PT_Restrict_PivotTable()
'Restrict pivot table functionality
Dim pf As PivotField
With ActiveSheet.PivotTables(1)
.EnableWizard = False
.EnableDrilldown = False
.EnableFieldList = False 'Excel 2002+
.EnableFieldDialog = False
.PivotCache.EnableRefresh = False
For Each pf In .PivotFields
'If pf.Value = "Data" Then End
With pf
.DragToPage = False
.DragToRow = False
.DragToColumn = False
.DragToData = False
.DragToHide = False
End With
Next pf
End With
End Sub
This works fine until it hits "Data". I can put a watch on it and see it
run through all of the pivot fields. It will run through each field coming
to "Data" last. When the pf value becomes "Data" the macro stops on
..DragToPage = False with an application defined or object defined error.
Any ideas ? I put an If statement (commented out above) that when the pf
value = "Data" then end. This works fine as long as the user doesn't change
"Data" to anything else, if they do then it's back to the same problem.
Should it read "Data" as a pivot field?
Data
TASK ID DESCRIPTION Labor Cost Other Cost
1.1 Base Year Labor $ 131,596 $ 9,527
2.1 Option Period 1 Labor $ 542,806 $ 39,296
3.1 Option Period 2 Labor $ 575,364 $ 41,653
4.1 Option Period 3 Labor $ 610,398 $ 44,189
5.1 Option Period 4 Lalbor $ 647,571 $ 46,880
Grand Total $2,507,735 $ 181,545