+ Reply to Thread
Results 1 to 6 of 6

Attach Labels to points in Scatter chart

  1. #1
    Registered User
    Join Date
    12-15-2010
    Location
    Oregon, USA
    MS-Off Ver
    Excel 2007
    Posts
    48

    Attach Labels to points in Scatter chart

    Hi Guys ,
    I am trying to attach labels to my data points in a scatter graph. I have a macro which works for one data series , but i have 3 data series and i am not able to modify it. Attach is the macro and sample data. Any help can be greatly appreciated.

    Thanks.

    Roop

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Roop; 06-20-2011 at 06:56 PM.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Attach Labels to points in Scatter chart

    In your code in the attachment, try changing the index of the series collection to 2 and 3 respectively - it seems to always be set at 1 at the moment.

    e.g.

    Please Login or Register  to view this content.
    Martin

  3. #3
    Registered User
    Join Date
    12-15-2010
    Location
    Oregon, USA
    MS-Off Ver
    Excel 2007
    Posts
    48

    Re: Attach Labels to points in Scatter chart

    Thanks Martin, it works

  4. #4
    Registered User
    Join Date
    12-15-2010
    Location
    Oregon, USA
    MS-Off Ver
    Excel 2007
    Posts
    48

    Re: Attach Labels to points in Scatter chart

    Hi Martin,
    Can you please explain what does this part of the code do. I tried to understand this but was unsuccessful.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-16-2013
    Location
    Huntsville, AL
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Attach Labels to points in Scatter chart

    Martin - I am having this same problem - trying to label multiple series in a scatter chart. The macro works fine for a single series bubble chart. I changed the index to 2 in the SeriesCollection references (code below), but I get a "Invalid procedure call or argument" error at the following statement:

    x1Vals = Mid(x1Vals, InStr(InStr(x1Vals, ","), x1Vals, _
    Mid(Left(x1Vals, InStr(x1Vals, "!") - 1), 9)))

    Any thoughts? Did I misunderstand your guidance on this post?


    Modified code:
    Sub AttachLabelsToPoints()

    'Dimension variables.
    Dim Counter1 As Integer, ChartName As String, x1Vals As String
    ' Disable screen updating while the subroutine is run.
    Application.ScreenUpdating = False

    'Store the formula for the first series in "xVals".
    x1Vals = ActiveChart.SeriesCollection(2).Formula


    ' 'Extract the range for the data from xVals.
    x1Vals = Mid(x1Vals, InStr(InStr(x1Vals, ","), x1Vals, _
    Mid(Left(x1Vals, InStr(x1Vals, "!") - 1), 9)))
    x1Vals = Left(x1Vals, InStr(InStr(x1Vals, "!"), x1Vals, ",") - 1)
    Do While Left(x1Vals, 1) = ","
    x1Vals = Mid(x1Vals, 2)
    Loop


    'Attach a label to each data point in the chart.
    For Counter1 = 1 To Range(x1Vals).Cells.Count
    ActiveChart.SeriesCollection(1).Points(Counter1).HasDataLabel = _
    True
    ActiveChart.SeriesCollection(1).Points(Counter1).DataLabel.Text = _
    Range(x1Vals).Cells(Counter1, 1).Offset(0, -1).Value
    Next Counter1




    End Sub

    thank you,

    ddholmes

  6. #6
    Registered User
    Join Date
    02-22-2013
    Location
    portugal
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Attach Labels to points in Scatter chart

    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

    ' Activate chart
    ActiveSheet.ChartObjects(1).Activate


    'Store the formula for the all series in "xVals".

    While (iii <= 8)

    iii = iii + 1
    Counter = 0

    While (Counter <= x) And (iii <= 8)

    xVals = ActiveChart.SeriesCollection(iii).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

    x = Range(xVals).Cells.count

    ActiveChart.SeriesCollection(iii).Points(Counter).HasDataLabel = _
    True

    ActiveChart.SeriesCollection(iii).Points(Counter).DataLabel.Text = _
    Range(xVals).Cells(Counter, 1).Offset(0, -1).Value

    ActiveChart.SeriesCollection(iii).Points(Counter).DataLabel.Select
    Selection.AutoScaleFont = True

    With Selection.Font
    .Name = "Arial"
    .FontStyle = "Regular"
    .Size = 6
    .Strikethrough = False
    .Superscript = False
    .Subscript = False
    .OutlineFont = False
    .Shadow = False
    .Underline = xlUnderlineStyleNone
    .ColorIndex = xlAutomatic
    .Background = xlAutomatic

    End With

    With Selection
    .NumberFormat = "0.000"
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlCenter
    .ReadingOrder = xlContext
    .Position = xlLabelPositionRight
    .Orientation = 0
    End With

    Next Counter

    Wend

    Wend

    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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