babou
babou

Reputation: 237

Change color of the last point in a graph


I created a graph in VBA

But i want to the last point i have done is in another color (red)

here is my code :

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

In i is the X abscisse and j is the Y abscisse of the last point !

thank you for any advice

Upvotes: 1

Views: 183

Answers (2)

babou
babou

Reputation: 237

Your code works but it does this :

enter image description here

Upvotes: 0

Matt M
Matt M

Reputation: 149

This code will set the last marker on the chart to red. Note the the RGB value for red is (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

Upvotes: 4

Related Questions