I have an Excel 2010 pivot table containing, at first, three row label fields.
I need to create a macro that will add a specific field as the label field of the bottom row in the pivot table. (For reasons that I will not enter, the user cannot add this field on his own.)
However, by the time the user starts this macro, they can add or remove some line labels.
This macro recorder gives me this when I add a field to the lowest position of the pivot table (with 3 row labels already selected):
With ActiveSheet.PivotTables("MyPivotTable").PivotFields("MyNewField") .Orientation = xlRowField .Position = 4 End With
If the user has added or deleted some elements, this position No. 4 is incorrect. How do I pass the correct position number into my code?
Trying to aim using Position = 99 gives me the following error:
Unable to set the Position property of the PivotField class
Any ideas please?
source share