更改图表中最后一个点的颜色

时间:2017-03-30 15:42:12

标签: vba excel-vba excel

我在VBA中创建了一个图表

但我想最后一点是用另一种颜色(红色)

这是我的代码:

Sub Macro2()
'
' Macro2 Macro
'

'

    i = Range("G3").Select

    j = Range("D3").Select

     With ActiveChart.ChartArea.Select
            i.MarkerBackgroundColor = RGB(250, 250, 250)
            j.MarkerForegroundColor = RGB(250, 250, 250)
    End With
End Sub

在i中我是X abscisse而j是最后一点的Y abscisse!

感谢您的任何建议

2 个答案:

答案 0 :(得分:4)

此代码会将图表上的最后一个标记设置为红色。请注意,红色的RGB值是(255,0,0)

Sub SetLastMarkerRed()

    Dim ws As Worksheet
    Dim ch As Chart
    Dim sc As SeriesCollection
    Dim s As Series
    Dim p As Point

    Set ws = ThisWorkbook.ActiveSheet
    Set ch = ws.ChartObjects(1).Chart
    Set sc = ch.SeriesCollection
    Set s = sc.Item(1)
    Set p = s.Points(s.Points.Count)
    p.MarkerBackgroundColor = RGB(255, 0, 0)
    p.MarkerForegroundColor = RGB(255, 0, 0)

    Set ws = Nothing
    Set ch = Nothing
    Set sc = Nothing
    Set s = Nothing
    Set p = Nothing

End Sub

enter image description here

答案 1 :(得分:0)

您的代码可以正常运行但是:

enter image description here