Hi John,
It is relatively easy to add lines to charts under VBA control the same way you would manually. Try recording a macro where you draw a horizontal and vertical line, and you will see what I mean. You will have to calculate the Top, Left, Height, and Width properties of the lines, and do some scaling based on the size of the chart. All graphic objects have Top, Left, Height and Width properties, so it is easy to determine where a chart is that is embedded on a worksheet, and its size. Of course, you will have to calculate the chart coordinates where the lines should be drawn based on x and y median value calculations.
The macro could either operate on just the selected chart, in which case you would have to run it 100 times, or, if you really want to add the lines to all charts, simply loop through all the chart objects in your workbook and run the code that generates the lines for each one. If you only want to add the lines to certain types of charts, you would want to add some code to check the chart type before adding them.
I realize that this is just a crude outline, but at least you know that it is not difficult--just a bit of a learning curve if you haven't done it before.
Happy charting.
Damon
Thanks, Damon. I have no experience with macros, so the learning curve will be a steep one! However, I can see the benefits of macros in this situation - heck, some of the best stuff in here was developed using macros! Could you suggest some resources and hints to help me along (articles, other examples, etc.)? Thank you very much for your response.
John
John,
I wish I knew what book to recommend. There are so many available now, a little time spent at your local bookstore looking over the options might be helpful. When I learned this stuff, I dug it out for myself because not so many books were available, and because I had a lot of previous experience writing my own graphics routines and with researching the object models of objects within Excel.
If I can get the time I will send you an example of some code to draw a line across each chart in a workbook.
Damon