У меня есть список данных, и мне нужно сгенерировать диаграмму для каждых двух строк и дать название диаграммы, связанной с 1-й строкой.Пример данных:
Пример
И т. Д.
Код, который я использую для создания диаграмм:
Sub loopChart()
Dim mychart As Chart
Dim myRange As Range
Dim c As Integer
Dim r As Integer
Dim s As Integer
Dim ttl As String
r = 2
While r <= 10 '1=dataSource1, 4=dataSource2, 7=dataSource3
'set data source for the next chart
With Worksheets("Sheet9")
Set myRange = .Range(.Cells(r, 2), .Cells(r + 1, 14))
End With
'create chart
Sheets("Chart").Select
ActiveSheet.Shapes.AddChart.Select
With ActiveChart
ttl = Range("A" & r)
.ChartType = xlLineMarkers 'xlLine
.SetSourceData Source:=myRange, PlotBy:=xlRows 'sets source data for graph including labels
.SetElement (msoElementLegendRight) 'including legend
.HasTitle = True
'dimentions & location:
.Parent.Top = 244 'defines the coordinates of the top of the chart
'.Parent.Left = r * 150 'defines the coordinates for the left side of the chart
.Parent.Height = 200
.Parent.Width = 300
.ChartTitle.Formula = ttl
End With
r = r + 2
Wend
End Sub
Итак, 1-й график, который генерирует, должен получить заголовок в строке 2, следующий график должен иметь заголовок строки 4 ... Я всегда получаю заголовок графика на 1-м графике, который генерирует, но не на любом другом графике.,Может ли кто-нибудь помочь мне в этом?