代码:
Sub NewSeries()
Dim i As Integer
i = 0
For A = Asc("A") To Asc("G")
For B = Asc("A") To Asc("F")
i = i + 1
Dim XV, YV As String
XV = Chr(A) + Chr(B) + "!$B$16:$B$79"
YV = Chr(A) + Chr(B) + "!$c$16:$c$79"
ActiveSheet.ChartObjects("图表 1").Activate
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(i).XValues = XV
ActiveChart.SeriesCollection(i).Values = YV
ActiveChart.SeriesCollection(i).Name = "系列" & I
Next B
Next A
End Sub
说明:excel有AA到GF共计42个数据表(每个表格格式一致),在一个表中插入一张空白散点图,上述代码可将42个数据表的B、C列部分数据生成散点图。