Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50090

How to rearrange rows in a dynamic Pivot Table

$
0
0
Hello Everybody!

I am still learning VBA and have been able to solve most of my problems using Google, but this one has stumped me. I want to sort my pivot chart but that will be done automatically after sorting the pivot rows (correct?)

anyway:

say I have a pivot table with rows:
1,2,3,4,5 (different status)

i would like to sort them into that order, when my code creates the table, it organizes them in a random order (im assuming as to what it finds first after running through the "Status" column while creating the table)

I have found this code online and modified it for my use:

Code:

.PivotFields("Status").PivotItems("1").Position = 1
.PivotFields("Status").PivotItems("2").Position = 2
.PivotFields("Status").PivotItems("3").Position = 3
.PivotFields("Status").PivotItems("4").Position = 4
.PivotFields("Status").PivotItems("5").Position = 5

however my table is dynamic. What i mean by that: It is possible that sometimes when the macro is run, there will be nothing denoted as status 1, in this case the code fails.

Can anyone please help me? Thank you for your time!

Viewing all articles
Browse latest Browse all 50090

Trending Articles