Results 1 to 2 of 2

Attach Labels to Points on Scatter Chart

Threaded View

  1. #1
    Registered User
    Join Date
    02-27-2014
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    20

    Attach Labels to Points on Scatter Chart

    Hi, I am using the following code to assign labels on a scatter chart but am having trouble with one of the lines. I sometimes receive an error on the following line and other times it works fine:
    "xVals = ActiveChart.SeriesCollection(1).Formula"
    The error message is "Object variable or With Block variable not set"
    I was wondering if someone might be able to help by explaining the cause of the problem?

    Many thanks.


    Sub AttachLabelsToPoints()
    
       'Dimension variables.
       Dim Counter As Integer, ChartName As String, xVals As String
    
       ' Disable screen updating while the subroutine is run.
       Application.ScreenUpdating = False
    
       'Store the formula for the first series in "xVals".
       xVals = ActiveChart.SeriesCollection(1).Formula
    
       'Extract the range for the data from xVals.
       xVals = Mid(xVals, InStr(InStr(xVals, ","), xVals, _
          Mid(Left(xVals, InStr(xVals, "!") - 1), 9)))
       xVals = Left(xVals, InStr(InStr(xVals, "!"), xVals, ",") - 1)
       Do While Left(xVals, 1) = ","
          xVals = Mid(xVals, 2)
       Loop
    
       'Attach a label to each data point in the chart.
       For Counter = 1 To Range(xVals).Cells.Count
         ActiveChart.SeriesCollection(1).Points(Counter).HasDataLabel = _
             True
          ActiveChart.SeriesCollection(1).Points(Counter).DataLabel.Text = _
             Range(xVals).Cells(Counter, 1).Offset(0, -1).Value
       Next Counter
    
    End Sub
    Last edited by ryanpetersen; 12-09-2014 at 06:07 PM. Reason: Updated with code tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Excel 2007 : Labels for Data Points on a Scatter Chart
    By ProfessorDJF in forum Excel Charting & Pivots
    Replies: 6
    Last Post: 09-12-2018, 12:47 PM
  2. Attach Labels to points in Scatter chart
    By Roop in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-15-2016, 04:45 AM
  3. Adding Labels to Data Points in Scatter Plot Chart
    By Stopea in forum Excel General
    Replies: 10
    Last Post: 05-21-2014, 08:25 PM
  4. Replies: 0
    Last Post: 04-01-2009, 10:54 AM
  5. [SOLVED] Macro to add labels to data points in an xy scatter chart
    By Scott Wagner in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 12-16-2005, 09:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1