Graph not plotting correctly if source not selected

  • Follow


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?
0
Reply Frank 6/6/2010 5:12:40 PM

Frank  -

Excel chart guru Jon Peltier has VBA code examples at

http://peltiertech.com/Excel/ChartsHowTo/QuickChartVBA.html

-  Mike
http://www.MikeMiddleton.com
Mike@DecisionToolworks.com


"Frank" <no.reply7@comcast.net> wrote in message 
news:ab71f33a-679d-4c45-871e-435fadb31fbc@j36g2000prj.googlegroups.com...
> 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? 

0
Reply Mike 6/6/2010 7:47:19 PM

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?
0
Reply Jon 6/7/2010 2:59:09 PM

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.
0
Reply Frank 6/7/2010 3:55:15 PM

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.
0
Reply Jon 6/7/2010 3:59:54 PM

Yep!

That works.

I'm learning every day.

Thanks
0
Reply Frank 6/7/2010 4:49:35 PM

5 Replies
827 Views

(page loaded in 0.077 seconds)


Reply: