如何防止excel在我的vba生成的图表中自动创建系列?

时间:2017-12-06 13:17:17

标签: excel vba charts

我正在尝试创建x列和y列的非常基本的散点图。

Dim c As Chart
Set c = sht.Shapes.AddChart.Chart
With c

    .ChartType = xlXYScatter
    .SeriesCollection.NewSeries
    .SeriesCollection(1).Name = "GPC Plot"
    .SeriesCollection(1).XValues = Range("B6", Range("B6").End(xlDown))
    .SeriesCollection(1).Values = Range("C6", Range("C6").End(xlDown))
    .HasTitle = True
    .ChartTitle.Characters.Text = sheetname
    .Axes(xlCategory, xlPrimary).HasTitle = True
    .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Molecular Weight"
    .Axes(xlCategory).MaximumScale = 10000
    .Axes(xlCategory).MinimumScale = 10
    .Axes(xlCategory).ScaleType = xlLogarithmic
    .Axes(xlValue).MaximumScale = 225
    .Axes(xlValue).MinimumScale = 0


End With

我只想要带有一个数据系列的图表,但Excel使用我正在创建图表的工作表中的随机数据生成一个包含5个其他系列的图表。有没有办法阻止excel自动执行此操作?

1 个答案:

答案 0 :(得分:0)

在添加所需数据之前,您需要从图表中清除数据。在With / End With块的开头,插入:

With c
    Do Until c.SeriesCollection.Count = 0
        c.SeriesCollection(1).Delete
    Loop
相关问题