View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson Greg Wilson is offline
external usenet poster
 
Posts: 747
Default charting code hanging up

The line that gets hung-up used to be contained inside a "With ActiveChart"
statement and now is contained inside a "With ActiveChart.Axes(xlCategory)"
statement. In other words, it used to be like saying:
"ActiveChart.Axes(xlValue, xlPrimary)..." which is syntactically correct.
Now it's like saying:
"ActiveChart.Axes(xlCategory).Axes(xlValue, xlPrimary)..." which is not
correct.

Your code could benefit from more efficient use of the "With ActiveChart"
statement. All statements beginning with "ActiveChart" could be contained
within this block statement and therefore you wouldn't need to qualify them.
This applies also to other With/End With statements - i.e. "With
ActiveChart.Axes(xlCategory)" and "With ActiveChart.PlotArea.Fill" could
become "With .Axes(xlCategory)" and "With .PlotArea.Fill" respectively if
they were already contained within a parent "With ActiveChart" statement.

Also, be advised that I get an error trying to change the properties of a
Line Chart, e.g. MaximumScale, MinimumScale etc. It works for me if the chart
is xlScatter. Are you sure you can do this? Maybe I'm just missing something
here. I'll leave it with you.

Regards,
Greg

"Papa Jonah" wrote:

I have some code that makes a chart and it works great. However, it only
works if the user's computer recognizes a user-defined chart type. In order
to get around it, I am just formating the chart with code.

This is a copy of a segment of the original code:
ActiveChart.ApplyCustomType ChartType:=xlUserDefined, TypeName:="LANL PI"
ActiveChart.SetSourceData Source:=Sheets("Data (altered)").Range( _
"A3:E" & numberrows & ",H3:H" & numberrows), PlotBy:=xlColumns
ActiveChart.SeriesCollection(1).Name = "=""Performance Index (PI)"""
ActiveChart.SeriesCollection(2).Name = "=""Trend"""
ActiveChart.SeriesCollection(3).Name = "=""Upper Control Limit"""
ActiveChart.SeriesCollection(4).Name = "=""Lower Control Limit"""
ActiveChart.SeriesCollection(5).Name = "='Data (altered)'!R21C6"

With ActiveChart
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = _
"Performance Index" & Chr(10) & "Larger Numbers are Better"
.Axes(xlCategory).MaximumScale = endchart '38270
.Axes(xlCategory).MinimumScale = 35339
.Axes(xlCategory).MinorUnit = 366
.Axes(xlCategory).MajorUnit = 366
.Axes(xlCategory).Crosses = xlCustom
.Axes(xlCategory).CrossesAt = 0
.Axes(xlCategory).ScaleType = xlLinear
.Axes(xlCategory).DisplayUnit = xlNone
End With


The user-defined code is nothing more than a line chart with a two-color
gradient.

I have changed the code to look like this:

ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets("Data (altered)").Range( _
"A3:E" & numberrows & ",H3:H" & numberrows), PlotBy:=xlColumns
ActiveChart.SeriesCollection(1).Name = "=""Performance Index (PI)"""
ActiveChart.SeriesCollection(2).Name = "=""Trend"""
ActiveChart.SeriesCollection(3).Name = "=""Upper Control Limit"""
ActiveChart.SeriesCollection(4).Name = "=""Lower Control Limit"""
ActiveChart.SeriesCollection(5).Name = "='Data (altered)'!R21C6"
With ActiveChart.Axes(xlCategory)

.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = _
"Performance Index" & Chr(10) & "Larger Numbers are Better" 'It
gets hung up here
.MaximumScale = endchart '38270
.MinimumScale = 35339
.MinorUnit = 366
.MajorUnit = 366
.Crosses = xlCustom
.CrossesAt = 0
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
With ActiveChart.PlotArea.Fill
.Visible = True
.ForeColor.SchemeColor = 35
.BackColor.SchemeColor = 22
End With

What would be making it get hung up at that point? That line worked before.
TIA