Can I grab graph coordinates in Excel via the mouse with VB?

C

Chris Manning

Is it possible to get the graph coordinates (i.e. the y coordinate of a
graph) in Excel using Visual Basic coding (or other methods) and insert them
into another cell? Specifically ,what I want to do is have the user click on
a graph, and have the y-coordinate at the time of the click entered into a
cell, or, alternatively, have the user click and drag across the graph and
have the coordinates at the beginning click and at the end of the drag
entered into two seperate cells. Further, the complete set of y-coordinates
is a column of data points, not a fcn if that helps at all.
 
C

Chip

Great articles. My question relates to gridlines. Can I click a gridline and
get all the datapoints that intersect that gridline. My chart will have time
as the x-axis with many elements graphed as lines. I would like to display
the values of all elements at a given time represented by the gridline.
 
J

Jon Peltier

It's not a native Excel feature, but if you're clever, you can probably
work it out. You need to determine which gridline was clicked, then go
through each series to find line segments that cross this value, and
interpolate the Y value at the time in question (unless you happen to
have actual data points for each series at this time value).

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______
 
J

Jon Peltier

Element ID is 15 (xlMajorGridlines) or 16 (xlMinorGridlines) when the gridlines are
selected.
Arg1 is always 1, since gridlines are only associated with primary axes.
Arg2 is 1 for the category (X) axis or 2 for the value (Y) axis.

Since you can only select the set of gridlines, not a single one, you cannot tell
which individual gridline was selected.

You can use a MouseUp event to get the X and Y coordinates of the click. These are
in chart window coordinates, not the X and Y of the chart axis coordinates. You can
determine which is the closest date based on this, but it takes a bunch of algebraic
calculations.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______
 
C

Chip

I had feared this originally. I am in a project that uses some built in
killer graphing that even allows you to slide the gridline and the data
populates the table but it is cumbersome so we were hoping that Excel could
repalce ost of it.
I guess not.
Thank you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top