Data labels: Method 'DataLabel' of object 'Point' failed

ehcpieterse

Active Member
Joined
Nov 16, 2006
Messages
278
hi, i am experiencing a seemingly strange error.

i have written a small piece of code to add data labels to a scatter plot (code below)

Sub ScatterLabels()

ActiveSheet.ChartObjects("Chart 1").Activate

For i = 1 To 42
ActiveChart.SeriesCollection(1).Points(i).DataLabel.Text = ActiveSheet.Cells(i + 1, 1).Value
Next i

ActiveSheet.ChartObjects("Chart 2").Activate

For i = 1 To 42
ActiveChart.SeriesCollection(1).Points(i).DataLabel.Text = ActiveSheet.Cells(i + 1, 1).Value
Next i

End Sub

This code works 100%, however, a different piece of code (below) on another sheet for a similar graph give s me the following error: "Method 'DataLabel' of object 'Point' failed". To me the code should work, but obviously i'm missing something.

Sub ScatterLabels2()

ActiveSheet.ChartObjects("Chart 2").Activate

For i = 1 To 42
ActiveChart.SeriesCollection(1).Points(i).DataLabel.Text = "ABC"
Next i

End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Does that series already have datalabels?
 
Upvote 0
no, the scatter plot only has data. i can manually add labels and even the recorded VBA code works if i manually add a data label for a specific point (code below)

Sub Macro7()

ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.SeriesCollection(1).Select
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.SeriesCollection(1).Points(30).Select
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.SeriesCollection(1).Points(30).DataLabel.Text = "ABC"
End Sub

am i doing something wrong?
 
Upvote 0
Try something like:
Code:
Sub ScatterLabels2()
   With ActiveSheet.ChartObjects("Chart 2").Chart.SeriesCollection(1)
      .HasDataLabels = True
      For i = 1 To 42
         .Points(i).DataLabel.Text = "ABC"
      Next i
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,710
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top