请vba高手帮指点一下这种情况怎样写代码!!!
发布网友
发布时间:2022-06-02 02:40
我来回答
共1个回答
热心网友
时间:2023-10-25 23:07
试编写代码示例如下:
Private Sub CommandButton1_Click()
Worksheets("Sheet1").ChartObjects(1).Activate
For i = 1 To ActiveChart.SeriesCollection.Count
ActiveChart.SeriesCollection(1).Delete
Next
ActiveChart.SeriesCollection.Add _
Source:=Range("B2,H2,N2,T2,Z2")
ActiveChart.SeriesCollection(1).Name = "=""语文"""
ActiveChart.SeriesCollection.Add _
Source:=Range("C2,I2,O2,U2,AA2")
ActiveChart.SeriesCollection(2).Name = "=""数学"""
ActiveChart.SeriesCollection.Add _
Source:=Range("D2,J2,P2,V2,AB2")
ActiveChart.SeriesCollection(3).Name = "=""英语"""
ActiveChart.SeriesCollection.Add _
Source:=Range("E2,K2,Q2,W2,AC2")
ActiveChart.SeriesCollection(4).Name = "=""物理"""
ActiveChart.SeriesCollection.Add _
Source:=Range("F2,L2,R2,X2,AD2")
ActiveChart.SeriesCollection(5).Name = "=""化学"""
ActiveChart.SeriesCollection.Add _
Source:=Range("G2,M2,S2,Y2,AE2")
ActiveChart.SeriesCollection(6).Name = "=""*"""
ActiveChart.ChartTitle.Text = "学生成绩统计表(" & Cells(2, 1) & ")"
End Sub
运行效果如图: