分享

如何用VBA批量生成图表和批量删除图表

 peng2009178 2019-05-12
Sub 批量生成图表()
Dim mydatesourse As Range 
For i = 2 To 5
    Set mydatesoure = Sheets("学生成绩表").Range("a" & i & ":d" & i)
    Charts.Add
    ActiveChart.ChartType = xlColumnClustered
    ActiveChart.SetSourceData Source:=mydatesoure, PlotBy:=xlColumns
    ActiveChart.Location where:=xlLocationAsObject, Name:=Sheets("学生成绩表").Name
    With ActiveChart
        .HasTitle = True
        .ChartTitle.Characters.Text = Sheets("学生成绩表").Range("a" & i) & "同学的成绩单"
        .Axes(xlValue, xlPrimary).HasTitle = True
        .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "成绩"
        .SetElement (msoElementLegendTop)
        .SeriesCollection(1).Name = "=学生成绩表!$B$1"
        .SeriesCollection(2).Name = "=学生成绩表!$C$1"
        .SeriesCollection(3).Name = "=学生成绩表!$D$1"
    End With
    ActiveChart.ChartArea.Select
Next
End Sub

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多