在excel中使用vba绘制43 xy散点图

时间:2016-01-16 02:44:52

标签: vba draw

我需要在excel中使用VBA绘制43 x / y散点图我为一个绘图开发了这个代码我不知道如何应用它来绘制剩余的42个绘图我的意思是我不想更改手动数据范围我需要把它放在for循环或类似的东西。这是我的代码

Sub draw()

    ActiveSheet.Shapes.AddChart2(240, xlXYScatterSmoothNoMarkers).Select
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.FullSeriesCollection(1).Name = "=""HBES"""
    ActiveChart.FullSeriesCollection(1).XValues = "=EN!$G$253:$G$278"
    ActiveChart.FullSeriesCollection(1).Values = "=EN!$H$253:$h$278"
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.FullSeriesCollection(2).Name = "=""NHBES"""
    ActiveChart.FullSeriesCollection(2).XValues = "=EN!$G$253:$G$278"
    ActiveChart.FullSeriesCollection(2).Values = "='EN1'!$g$253:$g$278"
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.FullSeriesCollection(3).Name = "=""NHBCS"""
    ActiveChart.FullSeriesCollection(3).XValues = "=EN!$G$253:$G$278"
    ActiveChart.FullSeriesCollection(3).Values = "=EN1c!$g$253:$g$278"
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.FullSeriesCollection(4).Name = "=""HBCS"""
    ActiveChart.FullSeriesCollection(4).XValues = "=EN!$G$253:$G$278"
    ActiveChart.FullSeriesCollection(4).Values = "=ENC!$h$253:$h$278"
    With ActiveChart
     'chart name
    .HasTitle = True
    .ChartTitle.Characters.Text = "Expected Number of Blockages for Pipes Group Two in Condition State One"
     'X axis name
    .Axes(xlCategory, xlPrimary).HasTitle = True
    .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time (Years)"
     'y-axis name
    .Axes(xlValue, xlPrimary).HasTitle = True
    .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Expected Number of Blockages"
End With
End Sub

请注意,数据按列排列,因此对于下一张图,我应该从

更改此行
ActiveChart.FullSeriesCollection(1).Values = "=EN!$H$253:$H$278"

ActiveChart.FullSeriesCollection(1).Values =“= EN!$ I $ 253:$ I $ 278”

和其余三个系列相同,x范围对于所有绘图都是常量

ActiveChart.FullSeriesCollection(3).XValues = "=EN!$G$253:$G$278"

我希望这很清楚

提前致谢

0 个答案:

没有答案
相关问题