LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Using VBA to swap between a clustered or separated column chart

Hi,

I have some data arranged on a worksheet like this...

A B
1 Name Data
2 Bob 8
3 John 12
4 Gary 10

I created the named range "ChartData" which is dynamic to allow
resizing if names and data are added or removed. In the above example
the range would consist of A2:B4

Next I created a chart on the spreadsheet that I want to plot the
named range "ChartData" in so that it is a clustered bar chart with a
legend containing the names.

In VBA I use the following code...
' Activate the chart
ActiveSheet.ChartObjects("Chart 1").Activate
' Add the data to the chart
ActiveChart.SetSourceData Source:=Range("Sheet1!ChartData")
' Give the x axis a name
ActiveChart.SeriesCollection(1).XValues = "={""Scores""}"

My problem is the data always comes out as separated columns and all
the same color (because they are the same series). The way to solve
this is manually right click on the chart, choose select data and then
swap rows/columns. The chart then becomes clustered and each name has
a different colored column and appears in the legend.

How can I alter my code/rearrange my data to get the clustered columns
automatically?

Thanks
Nick
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clustered and Stacked Column Chart Cassie Excel Discussion (Misc queries) 1 May 19th 09 01:23 AM
Creating a clustered column chart lauren Charts and Charting in Excel 1 December 4th 08 04:13 PM
2d-Column (Clustered Column) chart with Standard Deviation Bars Gary T Charts and Charting in Excel 1 November 28th 08 10:45 PM
Needed: Chart that combines clustered column and stacked column types Gerry Charts and Charting in Excel 3 February 14th 07 02:53 AM
combination clustered column and stacked bar chart John Charts and Charting in Excel 2 April 19th 05 03:49 PM


All times are GMT +1. The time now is 11:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"