ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Datalabels on Scatter (https://www.excelbanter.com/excel-programming/277070-datalabels-scatter.html)

Daniel Bonallack[_2_]

Datalabels on Scatter
 
I have 100 names of people in column A, with age in column
B and weight in Column C, and I've made a scatter graph
from this data, without any datalabels.

If a single datapoint is highlighted, I want a macro that
adds the relevant perons's name for that datapoint.

(Or, and I guess this is not possible, can that person's
name show up in the yellow tooltip as the mouse runs over
the label?)

Thanks in advance for any help.

Daniel



Walt Boraczek

Datalabels on Scatter
 
Daniel,

Assuming that your data labels are 1 column immediately to
the LEFT of your existing values, the following code will
work for you.

Good luck,
Walt

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

-----Original Message-----
I have 100 names of people in column A, with age in

column
B and weight in Column C, and I've made a scatter graph
from this data, without any datalabels.

If a single datapoint is highlighted, I want a macro that
adds the relevant perons's name for that datapoint.

(Or, and I guess this is not possible, can that person's
name show up in the yellow tooltip as the mouse runs over
the label?)

Thanks in advance for any help.

Daniel


.



All times are GMT +1. The time now is 04:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com