CaledoniaAZ
New Member
- Joined
- Sep 13, 2018
- Messages
- 3
Hello!
Need help with the VBA code to pull data from a column next to the data included on a chart in Excel 2013.
My data looks like this:
Name Rate Red Blue Green
Joe 15.00 25
Moe 17.00 27
Sue 18.00 31
Lew 20.00 40
Rod 25.00 45
The Rate is the y value and the colors are the x value (the dots on the chart are color-coded based on value).
I found this code on the Internet which produces a hover box and displays the y value (Rate). What I'd like is to have it display the Name column instead. How do I do this?
Private Sub Chart_MouseMove(ByVal Button As Long, ByVal Shift As Long, ByVal x As Long, ByVal y As Long)
Dim ElementID As Long
Dim Arg1 As Long
Dim Arg2 As Long
Dim chart_data As Variant
Dim chart_label As Variant
Dim last_bar As Long
Dim chrt As Chart
Dim ser As Series
On Error Resume Next
Me.GetChartElement x, y, ElementID, Arg1, Arg2
Set chrt = ActiveChart
Set ser = ActiveChart.SeriesCollection(1)
chart_data = ser.Values
chart_label = ser.XValues
Set txtbox = ActiveSheet.Shapes("hover")
If ElementID = xlSeries Then
If Err.Number Then
Set txtbox = ActiveSheet.Shapes.AddTextbox _
(msoTextOrientationHorizontal, x - 150, y - 150, 150, 40)
txtbox.Name = "hover"
txtbox.Fill.Solid
txtbox.Fill.ForeColor.SchemeColor = 9
txtbox.Line.DashStyle = msoLineSolid
chrt.Shapes("hover").TextFrame.Characters.Text = Application.WorksheetFunction.Text(chart_data(Arg2), "???.??")
With chrt.Shapes("hover").TextFrame.Characters.Font
.Name = "Arial"
.Size = 12
.ColorIndex = 16
End With
With chrt.Shapes("hover").TextFrame.Characters(Start:=1, Length:=11).Font
.Name = "Arial"
.Size = 12
.ColorIndex = 1
End With
last_bar = Arg2
End If
ser.Points(Arg2).Interior.ColorIndex = 44
txtbox.Left = x - 150
txtbox.Top = y - 150
Else
txtbox.Delete
ser.Interior.ColorIndex = 16
End If
End Sub
Need help with the VBA code to pull data from a column next to the data included on a chart in Excel 2013.
My data looks like this:
Name Rate Red Blue Green
Joe 15.00 25
Moe 17.00 27
Sue 18.00 31
Lew 20.00 40
Rod 25.00 45
The Rate is the y value and the colors are the x value (the dots on the chart are color-coded based on value).
I found this code on the Internet which produces a hover box and displays the y value (Rate). What I'd like is to have it display the Name column instead. How do I do this?
Private Sub Chart_MouseMove(ByVal Button As Long, ByVal Shift As Long, ByVal x As Long, ByVal y As Long)
Dim ElementID As Long
Dim Arg1 As Long
Dim Arg2 As Long
Dim chart_data As Variant
Dim chart_label As Variant
Dim last_bar As Long
Dim chrt As Chart
Dim ser As Series
On Error Resume Next
Me.GetChartElement x, y, ElementID, Arg1, Arg2
Set chrt = ActiveChart
Set ser = ActiveChart.SeriesCollection(1)
chart_data = ser.Values
chart_label = ser.XValues
Set txtbox = ActiveSheet.Shapes("hover")
If ElementID = xlSeries Then
If Err.Number Then
Set txtbox = ActiveSheet.Shapes.AddTextbox _
(msoTextOrientationHorizontal, x - 150, y - 150, 150, 40)
txtbox.Name = "hover"
txtbox.Fill.Solid
txtbox.Fill.ForeColor.SchemeColor = 9
txtbox.Line.DashStyle = msoLineSolid
chrt.Shapes("hover").TextFrame.Characters.Text = Application.WorksheetFunction.Text(chart_data(Arg2), "???.??")
With chrt.Shapes("hover").TextFrame.Characters.Font
.Name = "Arial"
.Size = 12
.ColorIndex = 16
End With
With chrt.Shapes("hover").TextFrame.Characters(Start:=1, Length:=11).Font
.Name = "Arial"
.Size = 12
.ColorIndex = 1
End With
last_bar = Arg2
End If
ser.Points(Arg2).Interior.ColorIndex = 44
txtbox.Left = x - 150
txtbox.Top = y - 150
Else
txtbox.Delete
ser.Interior.ColorIndex = 16
End If
End Sub