ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Graph not plotting correctly if source not selected (https://www.excelbanter.com/excel-programming/443117-graph-not-plotting-correctly-if-source-not-selected.html)

Frank[_28_]

Graph not plotting correctly if source not selected
 
Here my code:

Set Cht_level = Charts.Add
With Cht_level
.ChartType = xlLine
.SetSourceData Source:=cht_src
End With

if fails.

But if I

add cht_src.Select

before the code, it works brilliantly?

Why?

Mike Middleton[_2_]

Graph not plotting correctly if source not selected
 
Frank -

Excel chart guru Jon Peltier has VBA code examples at

http://peltiertech.com/Excel/ChartsH...kChartVBA.html

- Mike
http://www.MikeMiddleton.com



"Frank" wrote in message
...
Here my code:

Set Cht_level = Charts.Add
With Cht_level
.ChartType = xlLine
.SetSourceData Source:=cht_src
End With

if fails.

But if I

add cht_src.Select

before the code, it works brilliantly?

Why?



Jon Peltier[_2_]

Graph not plotting correctly if source not selected
 
How is cht_src defined?

- Jon
-------
Jon Peltier
Peltier Technical Services, Inc.
http://peltiertech.com/


On 6/6/2010 1:12 PM, Frank wrote:
Here my code:

Set Cht_level = Charts.Add
With Cht_level
.ChartType = xlLine
.SetSourceData Source:=cht_src
End With

if fails.

But if I

add cht_src.Select

before the code, it works brilliantly?

Why?


Frank[_29_]

Graph not plotting correctly if source not selected
 
Hi Jon

I've actaully look at your site. It look you set the chart source as
selection.

Here is my non-working code"

Set cht_src = Range(Range("A1").Offset(1, 2 * (c + 1) + 2),
Range("A1").Offset(Application.Count(Range("dist_x _axys")) + 1, 2 * (c
+ 1) + 2 + c))

Set Cht_level = Charts.Add
With Cht_level
.ChartType = xlLine
.SetSourceData Source:=cht_src
End With


here is my working code:

Set cht_src = Range(Range("A1").Offset(1, 2 * (c + 1) + 2),
Range("A1").Offset(Application.Count(Range("dist_x _axys")) + 1, 2 * (c
+ 1) + 2 + c))

cht_src.Select

Set Cht_level = Charts.Add
With Cht_level
.ChartType = xlLine
.SetSourceData Source:=cht_src
End With

The only difference is the cht_src.Select

I find it odd that you need to select the chart source in order to
graph it correctly.

Jon Peltier[_2_]

Graph not plotting correctly if source not selected
 
Frank -

I find this strange too.

What if you remove the .Select statement, then move .ChartType after
..SetSourceData?

- Jon
-------
Jon Peltier
Peltier Technical Services, Inc.
http://peltiertech.com/


On 6/7/2010 11:55 AM, Frank wrote:
Hi Jon

I've actaully look at your site. It look you set the chart source as
selection.

Here is my non-working code"

Set cht_src = Range(Range("A1").Offset(1, 2 * (c + 1) + 2),
Range("A1").Offset(Application.Count(Range("dist_x _axys")) + 1, 2 * (c
+ 1) + 2 + c))

Set Cht_level = Charts.Add
With Cht_level
.ChartType = xlLine
.SetSourceData Source:=cht_src
End With


here is my working code:

Set cht_src = Range(Range("A1").Offset(1, 2 * (c + 1) + 2),
Range("A1").Offset(Application.Count(Range("dist_x _axys")) + 1, 2 * (c
+ 1) + 2 + c))

cht_src.Select

Set Cht_level = Charts.Add
With Cht_level
.ChartType = xlLine
.SetSourceData Source:=cht_src
End With

The only difference is the cht_src.Select

I find it odd that you need to select the chart source in order to
graph it correctly.


Frank[_29_]

Graph not plotting correctly if source not selected
 
Yep!

That works.

I'm learning every day.

Thanks


All times are GMT +1. The time now is 05:07 PM.

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