|
参考までに
下のコードは「data」シートの範囲を元データとして、
「Sheet2」ワークシートのB列に 上から順に 一系列だけの
埋め込みグラフ(chartobject) を描画する例です。
Sub Try1()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim rngX As Range
Dim rngY As Range
Dim rngN As Range
Dim myLocation As Range
Dim chtObj As ChartObject
Set ws1 = Worksheets("data")
Set ws2 = Worksheets("Sheet2")
With ws1
Set rngX = .Range("B1").Resize(, 5)
Set rngY = rngX.Offset(1) '最初のグラフのY軸データ範囲
Set rngN = .Range("A2", .Cells(.Rows.Count, 1).End(xlUp))
End With
Set myLocation = ws2.Range("B2").Resize(15, 6) '最初にグラフをおく場所
Dim i As Long
For i = 1 To rngN.Count '系列の数だけ繰り返し
With myLocation
Set chtObj = .Worksheet.ChartObjects.Add( _
.Left, .Top, .Width, .Height)
End With
With chtObj.Chart
.ChartType = xlXYScatter
.SetSourceData Union(rngX, rngY)
.SeriesCollection(1).Name = rngN
.HasLegend = False
.HasTitle = False
End With
Set myLocation = myLocation.Offset(16) '次のグラフの場所
Set rngY = rngY.Offset(1) '次のY元データ範囲
Set rngN = rngN.Offset(1) '次の系列名範囲
Next
End Sub
|
|