Hi Andy,
I am working on a similar problem trying to use this macro to create
multiple line charts. (In my case, 10 charts for 10 series data) The codes
from this post are working but need some modifications for my purpose. Could
you please help me with my codes to put each chart into different worksheet
and maybe change the tab name of the worksheet to the series name in my data?
Also I was able to add the title for the chart and X, Y axises but not sure
how to also insert the series name into my chart title and move the Y axis to
buttom of the chart.... I am not a heavy excel user.....
Here are my codes:
Sub MakeCharts()
Dim rngData As Range
Dim rngHeader As Range
Dim rngDataRow As Range
Dim objChart As ChartObject
Dim sngTop As Single
Dim sngHeight As Single
Dim sngLeft As Single
Dim sngWidth As Single
Set rngHeader = Range("Y9:AE9")
Set rngData = Range("Y10", Range("Y10").End(xlDown)).Resize(, 7)
' chart dimension and start position
sngLeft = rngData.Left + rngData.Width
sngWidth = rngData.Width * 2
sngTop = rngData.Top
sngHeight = sngWidth * 0.45
For Each rngDataRow In rngData.Rows
Set objChart = ActiveSheet.ChartObjects.Add(sngLeft, sngTop,
sngWidth, sngHeight)
With objChart.Chart
.ChartType = xlLine
Do While .SeriesCollection.Count > 0
.SeriesCollection(1).Delete
Loop
With .SeriesCollection.NewSeries
.Name = rngDataRow.Offset(0, -1).Cells(1).Value
.XValues = rngHeader
.Values = rngDataRow
End With
.HasTitle = True
.ChartTitle.Characters.Text = "Total Weight Loss for Subject"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text =
"Elapsed Time (Weeks)"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Total
Weight Loss"
End With
sngTop = sngTop + sngHeight
Next
End Sub
Thank you in advance,
Aurora