Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
ChristofSchwarz
Partner Ambassador
Partner Ambassador

Macro AddExpression on 1st position?

I couldn't figure out, how to move (promote, demote) an expression in a chart (Pivot Table) using Macro. The chart.AddExpression method adds the new expression always at the end (as the last), but in my case I want to add an expression before the existing expressions on 1st position.

The method chart.MoveExpression from, to works only on StraightTableObjects, not pivots.

Any ideas how to move the positions of chart expressions?

-Christof

3 Replies
marcus_sommer

Hi Christof,

you could use MoveExpression - here an example from APIGuide:

rem create new straight table and switch places of expression columns

set chart = ActiveDocument.Sheets("Main").CreateStraightTable

chart.AddDimension "ProductType"

chart.AddExpression "sum(Amount)"

chart.AddExpression "count(Product)"

chart.MoveExpression 1,0

- Marcus

ChristofSchwarz
Partner Ambassador
Partner Ambassador
Author

Unfortunately, .MoveExpression method exists only in StraightTable objects, Pivots won’t allow it. As a workaround, I added Fast-Chart-Change types (Straight Table, Pivot Table), change the chart type to straight, make the MoveExpression, then change back. This is a bit tricky …

Thank you

-Christof

marcus_sommer

Yes, this would be my suggestion for this case then it's quite easy. I think an (worst) alternatively could be to read from the properties all expressions and give them then a new index-number and create the new expression and set the changed properties again ...

- Marcus