Quick Question- VBA to swap Pivot Table Fields

largeselection

Active Member
Joined
Aug 4, 2008
Messages
358
Quick question-

I'd like to put in some code to swap the first field item in the row label section. I can do this by specifying the specific field I want to remove, but how can I get rid of the current "first field" if I don't know what it is?

So I might have my Row Labels as:

Name
State
Region
Product

I'd like to remove "Name" and add "ID" instead at the first spot. So I could do this via:

Code:
Dim pt As PivotTable
pt.ManualUpdate = True
    ActiveSheet.PivotTables("Users").PivotFields("Name").Orientation = _
        xlHidden
    With ActiveSheet.PivotTables("Users").PivotFields("ID")
        .Orientation = xlRowField
        .Position = 1
    End With

But now say I want to do the reverse?
Basically, is it possible to do something like...
Code:
    ActiveSheet.PivotTables("Users").PivotFields(1).Orientation = _
        xlHidden

to remove the first row field?
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
I could also alternatively be OK with removing ALL row fields and then just adding back the ones I didn't want to delete if that would make the process simpler.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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