Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Scatter Chart Macro - Labels & Leader Lines

Status
Not open for further replies.

RachieD

Technical User
May 14, 2004
20
0
0
EU
I have added labels to a scatter chart using the below macro but would also like to add leader lines. I am not very familiar with VBA and borrowed the code for adding the labels. I would appreciate it if someone could let me know how to amend this code to add in leader lines also.

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

Thanks!
Rachel
 


Hi,

Please repost this thread in Forum707.

Also, as a matter of practice for generating VBA code, figure out how to accomplish your task on the sheet, then turn on your macro recorder and record the task. Then observe your recorded code, by toggling the VB Editor, alt+F11. Please post this code as well in forum707.

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks for the advice - I have reposted it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top