How do I swap (switch) axes on a chart?

MSC

New Member
Joined
Sep 23, 2004
Messages
44
I have a scatter chart (though I don't believe that matters), and I have positive nonzero values that correspond to the X axis and Y axis.

So that I can view the chart a little differently, how do I switch the axes?

I have a number of charts so I'd prefer not to do it manually. Excel help only showed how to move the Y axis to the left or right side of the chart, or how to move the X axis to the top or bottom, but didn't indicate how to swap the two.

Thanks,
Mike
 

tactps

Well-known Member
Joined
Jan 20, 2004
Messages
3,459
This macro will do it for you:

Sub Macro3()
XOne = ActiveChart.SeriesCollection(1).XValues
YOne = ActiveChart.SeriesCollection(1).Values
ActiveChart.SeriesCollection(1).XValues = YOne
ActiveChart.SeriesCollection(1).Values = XOne
ActiveChart.ChartArea.Select
End Sub
 

MSC

New Member
Joined
Sep 23, 2004
Messages
44
Thanks...let me be sure I'm using this properly:

I pasted that code into the VBA editor, and though I did nothing else, it saved it into my existing list of macros as Chart1.Macro3. I went to a tab which had a graph in it, then Tools, Macro, Macros, selected it and clicked Run.

However, it then quickly returned a dialog box titled Microsoft Visual Basic but only with the characters "400" below, with OK or Help as the options. Help only yielded an empty Help box with nothing inside it...

Next, I decided to Step Into. First time, I ran into that '400' error trying to execute the fifth line, ActiveChart.SeriesCollection(1).Values = XOne. I Stepped Into again - but did so from the VBA editor, not the tab with the graph, and this time, on that same line, I get a dialog box "Runtime error 1004: applic-defined or object-defined error."

Thanks for your help, --Mike
 

Forum statistics

Threads
1,078,083
Messages
5,338,087
Members
399,204
Latest member
DeSola

Some videos you may like

This Week's Hot Topics

Top