Excel VBA绘图

时间:2017-08-11 16:50:01

标签: excel-vba plot linegraph vba excel

我需要在按钮点击时使用VBA绘制一组数据的折线图。

它正确绘制数据,但图表的图例中还有其他项目。

以下是数据和图表的快照:

enter image description here

以下是代码:

Sub Button1_Click()
Range("A2:D12").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("Sheet2!$A$2:$D$12")
ActiveChart.ChartType = xlLine
     Dim ChrtSrs1 As Series, ChrtSrs2 As Series
    Set ChrtSrs1 = ActiveChart.SeriesCollection.NewSeries
    With ChrtSrs1
        .Name = "='Sheet2'!$B$2"
        .Values = "='Sheet2'!$B$3:$B$12"
        .XValues = "='Sheet2'!$A$3:$A$12"
    End With
    Set ChrtSrs2 = ActiveChart.SeriesCollection.NewSeries
    With ChrtSrs2
        .Name = "='Sheet2'!$C$2"
        .Values = "='Sheet2'!$C$3:$C$12"
        .XValues = "='Sheet2'!$A$3:$A$12"
    End With
End Sub

如何从图表中的图例中删除额外字段?

0 个答案:

没有答案