Help with Applying a Macro to All Series in Scatterplot

bombpop

New Member
Joined
May 5, 2015
Messages
1
Hi all,

I want to first acknowledge that I have also posted this question on excelforum.com. I am posting here as well because my question on the other site seems to be getting lost in the shuffle, and I am hoping for a reply today or tomorrow. Thanks so much for reading this :)

So - here's my question...

I am working with a scatterplot that contains 6 series. The x-axis data are actual salaries for a group of employees, and the y-axis data are predicted salaries (from a regression analysis) minus actual salaries. The employees are in six groups, so I've put a series for each group in the scatterplot in order to get the markers to look different. I have a macro that will add labels from Column A to the markers in Series 1, but it doesn't add the labels I want to any of the other series. (I am doing this because the default marker labels aren't very helpful for my purposes.) Here is the macro:

Code:
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

Any help you can offer regarding how to modify this to get it to work for all series is much appreciated!


Thanks!!!


(p.s. I haven't included a spreadsheet here because I can't share the data. However, if a mock data set would help, please let me know.)
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,214,925
Messages
6,122,303
Members
449,078
Latest member
nonnakkong

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