Hi there, I am trying to create a macro that will enable me to easily zoom in a graph, you know, like in picture editing programs where you draw a rectangle with the mouse by clicking, holding and releasing and the program will zoom on the selected area.
I can't believe Excel doesn't natively integrate this, by the way. Zooming in by changing the axis scale is a nightmare.
The problem I have encountered in creating such a macro is that I can't determining the EXACT x and y coordinates at any point of a plot. I have seen a similar post that I thought would give me the solution, here:
http://www.mrexcel.com/board2/viewtopic.php?t=195683&highlight=coordinates
But it doesn't help. This is what I have so far:
Option Explicit
Dim ChWide As Single
Dim ChLeft As Single
Dim ChTop As Single
Dim ChTall As Single
Dim xStart As Single
Dim xEnd As Single
Dim yStart As Single
Dim yEnd As Single
Dim Xcoord As Single
Dim Ycoord As Single
Private Sub Chart_MouseUp(ByVal Button As Long, ByVal Shift As Long, _
ByVal x As Long, ByVal y As Long)
With ActiveChart
With .PlotArea
ChWide = .InsideWidth
ChLeft = .InsideLeft
ChTop = .InsideTop
ChTall = .InsideHeight
End With
With .Axes(xlCategory)
xStart = .MinimumScale
xEnd = .MaximumScale
End With
With .Axes(xlValue)
yStart = .MinimumScale
yEnd = .MaximumScale
End With
End With
Xcoord = (((x - ChLeft) / ChWide)) * (xEnd - xStart)
Ycoord = (((y - ChLeft) / ChWide)) * (yEnd - yStart)
MsgBox ("X=" & Xcoord & " , Y=" & Ycoord)
End Sub
But it doesn't give me the right X and Y values in the MsgBox. Are the .InsideXXX properties I am using wrong? I can't find any others.
Thanks a lot
I can't believe Excel doesn't natively integrate this, by the way. Zooming in by changing the axis scale is a nightmare.
The problem I have encountered in creating such a macro is that I can't determining the EXACT x and y coordinates at any point of a plot. I have seen a similar post that I thought would give me the solution, here:
http://www.mrexcel.com/board2/viewtopic.php?t=195683&highlight=coordinates
But it doesn't help. This is what I have so far:
Option Explicit
Dim ChWide As Single
Dim ChLeft As Single
Dim ChTop As Single
Dim ChTall As Single
Dim xStart As Single
Dim xEnd As Single
Dim yStart As Single
Dim yEnd As Single
Dim Xcoord As Single
Dim Ycoord As Single
Private Sub Chart_MouseUp(ByVal Button As Long, ByVal Shift As Long, _
ByVal x As Long, ByVal y As Long)
With ActiveChart
With .PlotArea
ChWide = .InsideWidth
ChLeft = .InsideLeft
ChTop = .InsideTop
ChTall = .InsideHeight
End With
With .Axes(xlCategory)
xStart = .MinimumScale
xEnd = .MaximumScale
End With
With .Axes(xlValue)
yStart = .MinimumScale
yEnd = .MaximumScale
End With
End With
Xcoord = (((x - ChLeft) / ChWide)) * (xEnd - xStart)
Ycoord = (((y - ChLeft) / ChWide)) * (yEnd - yStart)
MsgBox ("X=" & Xcoord & " , Y=" & Ycoord)
End Sub
But it doesn't give me the right X and Y values in the MsgBox. Are the .InsideXXX properties I am using wrong? I can't find any others.
Thanks a lot