|
求助,加入for循环时一直出错,不知道是哪里的问题。
想画两个图,代码基本相同,就是数据引用位置和X轴日期不同。“实验”按钮是加入for循环后的,"画图"是单独写的两个。
Dim ch_kc1, ch_kc2 As ChartObject, ws, ws_gx As Worksheet, wb As Workbook, a As Variant, i, j As Integer
Temp_gx = "D:\BaiduNetdiskDownload\新建文件夹\煤焦-供需存.xlsx"
Set wb_gx = GetObject(Temp_gx)
Set ws_gx = wb_gx.Worksheets("图表数据")
Set ws = Worksheets(1)
Set ws_date = Worksheets("日期")
Set ch_kc1 = ws.ChartObjects.Add(ws.[b4].Left, ws.[b4].Top, 310, 190)
Set ch_kc2 = ws.ChartObjects.Add(ws.[i4].Left, ws.[i4].Top, 310, 190)
ch_kc1.Name = ws.[b2]
ch_kc2.Name = ws.[c2]
a = Array(ch_kc1, ch_kc2)
For i = 0 To 1
With a(i).Chart
.ChartType = xlLine
.DisplayBlanksAs = xlInterpolated
.HasTitle = True
.HasLegend = True
With .Legend
.Font.Size = 8
.Font.ColorIndex = 0
End With
.SeriesCollection.NewSeries
With .SeriesCollection(1)
.Values = ws_gx.Range(ws_gx.Cells(6, 1 + 5 * i), ws_gx.Cells(369, 1 + 5 * i))
.XValues = ws_date.Range("d2:d365")
.Name = ws_gx.Cells(5, 1 + 5 * i)
.AxisGroup = 1
End With
.SeriesCollection.NewSeries
With .SeriesCollection(2)
.Values = ws_gx.Range(ws_gx.Cells(6, 2 + 5 * i), ws_gx.Cells(369, 2 + 5 * i))
.XValues = ws_date.Range("e2:e365")
.Name = ws_gx.Cells(5, 2 + 5 * i)
.AxisGroup = 1
End With
.SeriesCollection.NewSeries
With .SeriesCollection(3)
.Values = ws_gx.Range(ws_gx.Cells(6, 3 + 5 * i), ws_gx.Cells(369, 3 + 5 * i))
.XValues = ws_date.Range("f2:f365")
.Name = ws_gx.Cells(5, 3 + 5 * i)
AxisGroup = 1
End With
.SeriesCollection.NewSeries
With .SeriesCollection(4)
.Values = ws_gx.Range(ws_gx.Cells(6, 4 + 5 * i), ws_gx.Cells(369, 4 + 5 * i))
.XValues = ws_date.Range("g2:g365")
.Name = ws_gx.Cells(5, 4 + 5 * i)
End With
End With
Next
|
|