I'm trying to make a lookup table from a efficiency chart found in a pdf. Cutting the chart and pasting is as background in a Excel chart is a good start, so far so good.
Now I want to use VBA to get mouse coordinates (and chart values) from the chart. It turned out to be very difficult.
Either my calculations are way off or Excel is playing trick on me cause I just can't get the values correct, no way, no how....
Private Sub Chart_MouseDown(ByVal Button As Long, ByVal Shift As Long, ByVal x As Long, ByVal y As Long)
Dim wLA As Double 'width of Left Axis
Dim wRA As Double 'width of Right Axis
Dim wPA As Double 'width of Plot Area
Dim lPA As Double 'left placement
Dim NoOfPointsFromLeftOnPlotArea As Double
Dim ActualWidthOfPlotArea As Double
Dim PercentOfPlotAreaWidth As Double
Dim XValueOnPlot As Double
wLA = Me.Axes(xlValue).Width
Debug.Print "wLA " & wLA
lPA = Me.PlotArea.Left
Debug.Print "lPA " & lPA
NoOfPointsFromLeftOnPlotArea = x - lPA - wLA
Debug.Print "NoOfPointsFromLeftOnPlotArea " & NoOfPointsFromLeftOnPlotArea
wRA = Me.Axes(xlValue, xlSecondary).Width
Debug.Print "wRA " & wRA
wPA = Me.PlotArea.Width
Debug.Print "wPA " & wPA
ActualWidthOfPlotArea = wPA - wRA - wLA
Debug.Print "ActualWidthOfPlotArea " & ActualWidthOfPlotArea
PercentOfPlotAreaWidth = NoOfPointsFromLeftOnPlotArea / ActualWidthOfPlotArea
XValueOnPlot = PercentOfPlotAreaWidth * 1000
MsgBox XValueOnPlot
End Sub
Bookmarks