Pivot Table Macro

jac3130

Board Regular
Joined
Dec 21, 2012
Messages
131
I've created a Pivot Table with 30+ fields. I've recorded the following macro to add the first field. I need help modifying the code so that it looks for and adds every field automatically. It'd save a lot of time.

Code:
Sub PTAdd()
'
' PTAdd Macro
'
'
    With ActiveSheet.PivotTables("PivotTable3").PivotFields("Assigned To")
        .Orientation = xlRowField
        .Position = 1
    End With
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Does anyone know how to modify the macro so that it'll add every field that is in the pivot table options?
 
Upvote 0
I've got a feeling PT doesn't allow you to add 30+ row fields but this should do what you're asking for:
Code:
Sub AddToPTRowField()

Dim i As Integer
Dim PT As PivotTable


On Error GoTo Err   'This line skips to the end when the code errors


Set PT = ActiveSheet.PivotTables(1)


    With PT
        For i = 1 To 100
            With .PivotFields(i)
                .Orientation = xlRowField
            End With
        Next i
    End With


    Exit Sub


Err:


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,615
Messages
6,120,538
Members
448,970
Latest member
kennimack

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