interact with point's label

Guys,

The attached xls file has a macro which enables me to do an action when i click on any point/marker on the xychart. What i want now is to do the same this for the label in which if i click on it ,it will do the same action that is assigned when i click on the point/marker. Usually when someone clicks on the label, the text in it will be highlighted to enable you to edit it, so I don't know how we can come over this.

chartevents3.xls
bsaisuAsked:
Who is Participating?
 
andrewssd3Connect With a Mentor Commented:
Try this to replace your Chart_Select routine:
Private Sub objChart_Select(ByVal ElementID As Long, ByVal Arg1 As Long, ByVal Arg2 As Long)

    Dim s As Excel.Series
    Dim p As Excel.Point
    Dim d As Excel.DataLabel
    
    Select Case ElementID
    
        Case xlSeries
    
            Set s = objChart.SeriesCollection(Arg1)
            Debug.Print Arg2
            If Arg2 > -1 Then
                Set p = s.Points(Arg2)
                p.Select
            Else
                Set p = s.Points(1)
                s.Select
                Arg2 = 1
            End If
            MsgBox s.Name & vbTab & s.XValues(Arg2) & vbTab & s.Values(Arg2)
            
        Case xlDataLabel
    
            Set s = objChart.SeriesCollection(Arg1)
            Debug.Print Arg2
            If Arg2 > 0 Then
                Set d = s.DataLabels(Arg2)
                d.Select
            Else
                Set d = s.DataLabels(1)
                s.DataLabels.Select
                Arg2 = 1
            End If
            MsgBox s.Name & vbTab & s.XValues(Arg2) & vbTab & s.Values(Arg2)
    End Select
     
End Sub

Open in new window

0
 
Rory ArchibaldConnect With a Mentor Commented:
Try this version of the Select event in your class:
Private Sub objChart_Select(ByVal ElementID As Long, ByVal Arg1 As Long, ByVal Arg2 As Long)

   Dim s                 As Excel.Series
   Dim p                 As Excel.Point

   On Error GoTo err_handler
   Application.EnableEvents = False
   If ElementID = xlSeries Or ElementID = xlDataLabel Then
      If TypeName(Selection) <> "DataLabels" Then

         Set s = objChart.SeriesCollection(Arg1)
         Debug.Print Arg2
         If Arg2 > -1 Then
            Set p = s.Points(Arg2)
            p.Select
         Else
            Set p = s.Points(1)
            Application.EnableEvents = False
            s.Select
            Arg2 = 1
         End If
         MsgBox s.Name & vbTab & s.XValues(Arg2) & vbTab & s.Values(Arg2)
      End If
   End If

clean_up:
   Application.EnableEvents = True
   Exit Sub

err_handler:
   MsgBox Err.Description
   Resume clean_up


End Sub

Open in new window

0
 
bsaisuAuthor Commented:
Guys both of your solution is working but i think I would go with andrewssd3's solution because it seems slightly better.
rorya, your solution is good but in your solution I have to click on the point or the label twice to trigger the event. andrewssd3 has fixed this

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.