Trying to automate a Pivot

Nothnless

Board Regular
Joined
Apr 28, 2016
Messages
142
Hi,

I'm trying to automate a pivot using VBA by taking the values in a column and adding them to the rows section of a pivot table.

I found this code below that work well for a single value:

VBA Code:
ActiveSheet.PivotTables("PivotTable1").PivotFields("Product").Orientation = xlRowField
ActiveSheet.PivotTables("PivotTable1").PivotFields("Product").Position = 1

But I need help with something like below to add all the values from a column:

VBA Code:
Dim IntNumber As Long
Dim rngRows As Range
Dim FindMe As Range

IntNumber = 0

For Each FindMe In rngRows
ActiveSheet.PivotTables("PivotTable1").PivotFields("FindMe").Orientation = xlRowField
ActiveSheet.PivotTables("PivotTable1").PivotFields("FindMe").Position = IntNumber + 1
Next FindMe
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,215,036
Messages
6,122,796
Members
449,095
Latest member
m_smith_solihull

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