(Solved) – Run-time error 424 Object required (Points Object) VBA


I’m trying to make the final data point in my scatter plot “highlight” and be identified. Using:
https://docs.microsoft.com/en-us/office/vba/api/excel.points(object) I came up with the line of code .FullSeriesCollection(1).Points(Points.Count).ApplyDataLabels Type:=xlShowValue
which is supposed to add a label to the last point in series 1.

Not sure why but I get the error

Run-time error ‘424’: Object required

Here is my full code:

Sub Graph()

    Dim my_range As Range, t, co As Shape 

    t = Selection.Cells(1, 1).Value   " - "   ActiveSheet.Name

    Dim OldSheet As Worksheet
    Set OldSheet = ActiveSheet

    Set my_range = Union(Selection, ActiveSheet.Range("A:A"))

    Set co = ActiveSheet.Shapes.AddChart2(201, xlLine) 'add a ChartObject

    With co.Chart
        .FullSeriesCollection(1).ChartType = xlXYScatter
        .FullSeriesCollection(1).AxisGroup = 1
        .FullSeriesCollection(1).Points(Points.Count).ApplyDataLabels Type:=xlShowValue
        .FullSeriesCollection(2).ChartType = xlLine
        .FullSeriesCollection(2).AxisGroup = 1
        .SetSourceData Source:=my_range
        'highlight final dot of data
        .HasTitle = True
        .ChartTitle.Text = t
        ResolveSeriesnames co.Chart
        .Location Where:=xlLocationAsObject, Name:="Graphs"

    End With

End Sub

Here is my sample data

enter image description here

Leave a Reply

Your email address will not be published. Required fields are marked *