VBA Chart Switch Row/Column Help

nocturnal028

New Member
Joined
Aug 13, 2008
Messages
9
Is there a way in VBA to do the equivalent of pushing the 'Switch Row/Column' button seen in the Excel 2007 chart wizard when selecting the data range for a chart?

Essentially my chart data range is correct but the x and y axis values are backwards. I am trying to avoid having to write statements to add each individual series collection with an associated .XValue to force the data to be on the right axis.

I'd like to be able to use my one "ActiveChart.SetSourceData Source:=" line of code to set the data range instead of doing multiple .SeriesCollection.NewSeries (then also setting the .Name, .Values and .XValues) lines for each series. Then ideally after the one "ActiveChart.SetSourceData Source:=" line of code I would have a line of code telling the axis values to switch and all of my pain would be gone!

Does a line of code to tell the values to switch exist?
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Thank you for posting your own answer. I think you just saved me a few hours of work. I try to do this when I come across my own answers as well.
 
Upvote 0
I found the answer to my own question... If anyone else comes up against this, the VBA code to switch the data being dsiplayed back and forth between the x and y axis on a chart is:

ActiveChart.PlotBy = xlColumns
ActiveChart.PlotBy = xlRows


This indeed is a very useful TIP to SWAP from ROWS TO COLUMNS..

THanks a lot

Warm Regards
all4excel
 
Upvote 0
Just wanted to say that 10 years after OP this just saved me a ton of time and headache. Thanks for posting your own solution!
 
Upvote 0
I found the answer to my own question... If anyone else comes up against this, the VBA code to switch the data being dsiplayed back and forth between the x and y axis on a chart is:

ActiveChart.PlotBy = xlColumns
ActiveChart.PlotBy = xlRows

Tiptop. Saved much heartache. Excel macro recording didn't record this, so your insight was invaluable.
 
Upvote 0
I found the answer to my own question... If anyone else comes up against this, the VBA code to switch the data being dsiplayed back and forth between the x and y axis on a chart is:

ActiveChart.PlotBy = xlColumns
ActiveChart.PlotBy = xlRows
After your posting today 1821 days ago it saved me a lot of trial and error,
Thanls for sharing it here(y)(y):cool:
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

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