Loop While add Fields to Pivot Table

GooseNL

New Member
Joined
Apr 23, 2011
Messages
2
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
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi Herbert,

Thanks for the reply. However I am using excel 2003 and am not sure if I can use your examples.

Cheers, Goose
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top