|
-
Jun 8th, 2007, 04:37 PM
#1
Thread Starter
New Member
How to create a correct chart using VBA?
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 below, 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? Please see the attachment but I'm not sure it's attached.
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
-
Jun 8th, 2007, 05:34 PM
#2
Re: How to create a correct chart using VBA?
-
Jun 9th, 2007, 05:50 PM
#3
Hyperactive Member
Re: How to create a correct chart using VBA?
If you want multiple lines on a graph, each line is referred to as a series... and you have to set the source of each of these series... Here is some code you can easily implement into your own...
Sub AddNewSeries()
With ActiveChart.SeriesCollection.NewSeries
.Name = "My Series"
.Values = ActiveSheet.Range("G4:G14")
.XValues = ActiveSheet.Range("A4:A14")
End With
End Sub
-
Jun 9th, 2007, 07:07 PM
#4
Re: How to create a correct chart using VBA?
If you're going to set the chart type as xlLineMarkersStacked in the 5th line of your code, i.e. stacking the data up, then I don't know what else you'd expect.
Try xlLineMarkers instead.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|