Hi,
I am adding fields to a pivot table using the following macro. I would like to loop the fields until a counter reaches a set value.
Sub MacroAdd()
With ActiveSheet.PivotTables("Draaitabel2").PivotFields("trial3")
.Orientation = xlColumnField
.Position = 1
End With
Range("C3").Select
ActiveSheet.PivotTables("Draaitabel2").PivotFields("trial3").Orientation = _xlHidden
ActiveSheet.PivotTables("Draaitabel2").AddDataField ActiveSheet.PivotTables( _"Draaitabel2").PivotFields("trial2"), "2", xlSum
End Sub
I was thinking of adding something like this:
For x = 2 to 10
ActiveSheet.PivotTables("Draaitabel2").AddDataField ActiveSheet.PivotTables( _"Draaitabel2").PivotFields("trial" & x), (x), xlSum
Next x
But that gives an error.
Can anyone point me in the right direction?
Cheers, GooseNL
I am adding fields to a pivot table using the following macro. I would like to loop the fields until a counter reaches a set value.
Sub MacroAdd()
With ActiveSheet.PivotTables("Draaitabel2").PivotFields("trial3")
.Orientation = xlColumnField
.Position = 1
End With
Range("C3").Select
ActiveSheet.PivotTables("Draaitabel2").PivotFields("trial3").Orientation = _xlHidden
ActiveSheet.PivotTables("Draaitabel2").AddDataField ActiveSheet.PivotTables( _"Draaitabel2").PivotFields("trial2"), "2", xlSum
End Sub
I was thinking of adding something like this:
For x = 2 to 10
ActiveSheet.PivotTables("Draaitabel2").AddDataField ActiveSheet.PivotTables( _"Draaitabel2").PivotFields("trial" & x), (x), xlSum
Next x
But that gives an error.
Can anyone point me in the right direction?
Cheers, GooseNL