VBA to move pivot table field name to rows

Access Beginner

Active Member
Joined
Nov 8, 2010
Messages
311
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I have a bit of code that will move a field name in a pivot table to Rows. When I record the macro this field name is hard coded ( see example below).

What I'd like to do is have the hard code value replaced with a value in a cell, so I can have data validation in this cell and change it rather than going into the code each time.

In the 2nd example below I've tried something which I thought might work, but sadly it doesn't.


Snipet of existing code
Code:
With ActiveSheet.PivotTables("ReasonPivotTable").PivotFields("Reason name")
        .Orientation = xlRowField
        .Position = 1
    End With

Snippet of code I'm trying to replace it with
Code:
Dim PtableRowI As Variant


Set PtableRowI = Sheets("DataRequestPt").Range("E3")


With ActiveSheet.PivotTables("ReasonPivotTable").PivotFields.(PtableRowI)
            .Orientation = xlRowField
            .Position = 1
End With
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Forum statistics

Threads
1,214,983
Messages
6,122,595
Members
449,089
Latest member
Motoracer88

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