Results 1 to 4 of 4

Data Labeling Macro Problems

Threaded View

ryanbrenton Data Labeling Macro Problems 07-20-2011, 03:47 AM
docMed Re: Data Labeling Macro... 07-20-2011, 03:48 AM
ryanbrenton Re: Data Labeling Macro... 07-20-2011, 03:57 AM
docMed Re: Data Labeling Macro... 07-20-2011, 04:00 AM
  1. #1
    Registered User
    Join Date
    07-20-2011
    Location
    Gainesville, Florida
    MS-Off Ver
    Excel 2007
    Posts
    3

    Data Labeling Macro Problems

    I have a macro that I´ve been using to label series data points on a chart with a desired name rather than with the coordinate points. The macro works very well except for one thing, it is only meant to make one series. I would like to add a loop to it to make it be able to plot multiple series and label their data points. I´m not sure if this would work but ideally I would like to have the code distinguish a new series whenever there is a blank row in the data.
    So for example:

    AG32 4 5
    BC78 3 6
    HA23 2 0

    AN32 4 6
    JK12 2 6

    I would like the code to creat two series one with AG32-HA23 with labeled data points and one with AN32-JK12 with labeled data points, and on the same graph.


    The code I have looks like this:


    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

    I think I could add series with an outer loop to the format routine that looks something like


    For series =1 to n
       For each element in series n to number of elements in the series
       ...
       Next element
    Next series

    but I really don´t know the syntax of VBA at all and I´m honestly not a programmer. Could anyone show me how to do this and repost the edited code?

    Thanks
    Last edited by ryanbrenton; 07-20-2011 at 04:09 AM.

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