ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SourceData for graph (https://www.excelbanter.com/excel-programming/339511-sourcedata-graph.html)

Caroline

SourceData for graph
 
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
--
caroline

Tushar Mehta

SourceData for graph
 
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

In article ,
says...
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



All times are GMT +1. The time now is 09:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com