VBA 改变Excel图标序列颜色

Public Sub changeColor()

  For i = 1 To Worksheets("sheet1").ChartObjects.Count  '//统计总共有几个图

  Worksheets("sheet1").ChartObjects(i).Activate  '/*激活一个图表*/
    With ActiveChart

    For j = 1 To .SeriesCollection.Count '/获取当前图表中的序列数量

     If .SeriesCollection(j).Name = "A" Then '根据序列名称来判断

      .SeriesCollection(j).Border.Color = RGB(255, 0, 0) '根据RGB确定线条颜色

      .SeriesCollection(j).MarkerBackgroundColor = RGB(255, 0, 0)  '/更改数据标志的点的颜色

      .SeriesCollection(j).MarkerForegroundColor = RGB(255, 0, 0)


   End If

   If .SeriesCollection(j).Name = "B" Then

      .SeriesCollection(j).Border.Color = RGB(0, 255, 0)

      .SeriesCollection(j).MarkerBackgroundColor = RGB(0, 255, 0)

      .SeriesCollection(j).MarkerForegroundColor = RGB(0, 255, 0)

   End If

   If .SeriesCollection(j).Name = "C" Then

      .SeriesCollection(j).Border.Color = RGB(0, 0, 255)

      .SeriesCollection(j).MarkerBackgroundColor = RGB(0, 0, 255)

      .SeriesCollection(j).MarkerForegroundColor = RGB(0, 0, 255)

   End If

   If .SeriesCollection(j).Name = "D" Then

      .SeriesCollection(j).Border.Color = RGB(31, 95, 39)

      .SeriesCollection(j).MarkerBackgroundColor = RGB(31, 95, 39)

      .SeriesCollection(j).MarkerForegroundColor = RGB(31, 95, 39)

   End If

   Next

   End With

  Next
 End Sub

cnliutz

计算机基础教师

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注