Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a chart as expected using VBA

Status
Not open for further replies.

feipezi

IS-IT--Management
Aug 10, 2006
316
US
Hi,
I used the following code trying to create a chart but the lines showing in the chart are sort of accumulation of the data source, which is not what I expected. They should be individually showing themselves instead of summing up.
Is there any way to get what I expected?
Thanks in advance.

Sub CreateChart()
'On Error Resume Next
Range("A3:N21").Select
Charts.Add
ActiveChart.ChartType = xlLineMarkersStacked
ActiveChart.SetSourceData Source:=Sheets("GraphDisplayMKT").Range("C24:N30"), _
PlotBy:=xlRows
ActiveChart.Location Where:=xlLocationAsObject, Name:="GraphDisplayMKT"
With ActiveChart
.HasTitle = True
.HasLegend = False
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "BRA Share"
.ChartTitle.Characters.Text = "BRA Product"
.HeightPercent = 60
End With
With ActiveSheet.Shapes("Chart 1")
.ScaleHeight 1.39, msoFalse, msoScaleFromBottomRight
.ScaleWidth 1.5, msoFalse, msoScaleFromBottomRight
.ScaleHeight 0.77, msoFalse, msoScaleFromTopLeft
.ScaleWidth 1.22, msoFalse, msoScaleFromTopLeft
End With
ActiveChart.ChartArea.Select
With Selection.Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 7
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
ActiveChart.Legend.Delete = True
On Error GoTo 0
End Sub
 




Hi,

"... sort of accumulation of the data source, ..."
Code:
ActiveChart.ChartType = xlLineMarkers[b]Stacked[/b]
What did you expect"



Skip,

[glasses] [red][/red]
[tongue]
 
Thanks, Skip, for the tip. You were right about the ChartType. I was supposed to use 'xlLineMarkers', not 'xlLineMarkersStacked'.
You're the man.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top