+ Reply to Thread
Results 1 to 2 of 2

Update Scatter Plot Labels when data is updated?

  1. #1
    Registered User
    Join Date
    03-04-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    3

    Update Scatter Plot Labels when data is updated?

    I have successfully implemented the code below to attach data labels to a series of data.

    However, when the source data is updated, the data points move on the chart - but rerunning the Macro does not adjust the labels to the newly placed data points.

    Any help on what I can adjust in the following code to reset the labels would be greatly appreciated! Thank you!

    Sub Attach_Labels_toCharts()

    'ATTACH LABELS TO CHART
    '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

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Update Scatter Plot Labels when data is updated?

    Try something like this...

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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