SourceData for graph

C

caroline

If I use the following code, the CatTitle, ChartYear, SrcRange are graphed as
series.
I would like the CatTitle to be the title of the graph legend, the ChartYear
to be the Xaxis and the ScrRange the series to graph.
Can somebody help? thanks



Dim TheChartObj As ChartObject
Dim TheChart As Chart
Dim ChartYear As Range
Dim CatTitles As Range
Dim SrcRange As Range
Dim SourceData As Range

Set TheChartObj = ActiveSheet.ChartObjects(10)
Set TheChart = TheChartObj.Chart
Set SrcRange = Range(ActiveCell.Offset(0, 2), ActiveCell.Offset(0, 24))
Set ChartYear = Range("f3:ab3")
Set CatTitle = ActiveCell

Set SourceData = Union(CatTitle, ChartYear, SrcRange)

TheChart.SetSourceData _
Source:=SourceData, PlotBy:=xlRows

TheChartObj.Visible = True
 
T

Tushar Mehta

Why not set the series name, values, and xvalues to the respective
ranges?

To get one form of the syntax, use the macro recorder. An alternative
would be direct range references along the lines of

ActiveChart.SeriesCollection(1).XValues = Range("c2:c5")
ActiveChart.SeriesCollection(1).Values = Range("d2:d5")
ActiveChart.SeriesCollection(1).Name = Range("C1")

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top