Home » excel » excel – How do I determine the position of a tick in x-axis of a graph?

excel – How do I determine the position of a tick in x-axis of a graph?

Posted by: admin April 23, 2020 Leave a comment

Questions:

I want to get position(x,y) of a tick in x-axis of a graph to manual draw a line according it, please help me!
Please view below image to get my clearly question:
enter image description here

How to&Answers:

You can get the Y coordinate of all x-axis ticks like this: y = ActiveChart.Axes(xlValue).CrossesAt. In your example image, this will be 0.

The ticks on the x-axis will have X coordinates between ActiveChart.Axes(xlCategory).MinimumScale and ActiveChart.Axes(xlCategory).MaximumScale, both inclusive, at intervals of ActiveChart.Axes(xlCategory).MajorUnit.

Of course, if you know ahead of time which X value you want to highlight, then that X will be the X coordinate of the tick.

The above is assuming your chart is selected/activated. Instead of ActiveChart, you can use ActiveSheet.ChartObjects("Chart 1").Chart or whatever the correct reference to your chart is.

EDIT: Just realized that the example you show is a Line chart. It won’t be possible to do what you’re asking on a Line chart. You have to change the chart type to an XY (Scatter) chart first.