Quick question re: Labeling Data Points in ScatterPlot

largeselection

Active Member
Joined
Aug 4, 2008
Messages
358
So I'm almost there.

I'm using some stuff I found from Andrew Poulsom to add labels to a scatterplot based on the Ch_MouseDown event. The issue that I'm having is changing the reference in the text to a different cell.

Basically I want to pull back the UserID # which is in column B. So the code I'm using is:

Code:
Private Sub Ch_MouseDown(ByVal Button As Long, ByVal Shift As Long, ByVal x As Long, ByVal y As Long)
    Dim Txt As String
    Txt = ""
    Ch.GetChartElement x, y, IDNum, a, b
    If IDNum = xlSeries Then
        With ActiveChart.SeriesCollection(a).Points(b)
             .HasDataLabel = True
            Txt = "Series " & .Parent.Name
            Txt = Txt & " point " & b
            Txt = Txt & " (" & .DataLabel.Text & ")"
            Txt = Txt & " - " & Range("B28:B128").Cells(b, 1).Value

This works well and puts at the end of the label the value of the cell in column B using the selected points index value as the row.

However, my serieses (sp?) are built based on values within the cells and are not sequential. I have tried to change the Range in the last row of the code to my defined range from the other part of code and I've tried to change it to the range of Xvalues, but nothing works.


I thought to use Range(XValues).Cells(b,1).value might work because when I recorded a macro (which I then used to help build the code that creates the ranges) the code I used was
Code:
ActiveChart.SeriesCollection(1).XValues = "=Sheet1!$D25, Sheet1!$D45, Sheet1$D52, etc"

so I thought if I could use that range (XValues) as the range in the last row of code I could pull the selected point's index from within that range (and thus the fact that my series are not in sequential row order would not be a problem)

Ideally I would want the text that it pulls back to read:

Assuming I clicked on SeriesCollection(1), Points(3). I would want it to throw back as my "label". The third point in that series' Xvalues address offset by -2.

So it would see that I clicked on 1st Series and 3rd point and it would look at the XValues range in that series and choose the 3rd point (in this case being = Sheet1!$D52), then offset by -2 and return the value in cell B52.

Sorry if this is confusing, but I'm at my wits end with this. I've tried every combo under the sun that I can think of and I keep getting sub undefined or doesn't support that method errors.

Any help/links would be greatly appreciated
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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