Peltier Tech Blog

Excel Chart Add-Ins | Training | Custom Solutions | Charts and Tutorials | PTS Blog

 

Main menu:

 
Peltier Tech
Chart Add-Ins

Peltier Tech Waterfall Chart Utility
Peltier Tech Cluster-Stack Chart Utility
Peltier Tech Box and Whisker Chart Utility
Peltier Tech Marimekko Chart Utility
Peltier Tech Dot Plot Utility
Peltier Tech Cascade Chart Utility

 
Excel Dashboards

Subscribe

Site search

Subscribe

Site search


Recent Posts

Recently Commented

Popular Posts

Archive


 

Categories


 

Privacy Policy

Creative Commons License
Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.

Connect Two XY Series with Arrows – 2007 Error

by Jon Peltier
Wednesday, June 3rd, 2009
Peltier Technical Services, Inc., Copyright © 2010.
Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.

I came across a strange bug in Excel 2007 which will cause a number of programs to fail. I was going over the code in my Connect Two XY Series with Arrows post from May 2008, and decided to try it inExcel 2007. The result was unexpected.

The program was designed to connect corresponding points of two XY series in a chart, with arrows pointing from the point in the first series to its partner in the second. Starting with a chart like this:

The program produces this effect in Excel 2003 and earlier.

Pretty cool.

Now run the same procedure on the same chart in Excel 2007, and the result is completely not what you expected. The arrows are all pointing straight downward, and not located near the points they are supposed to connect.

The culprit is the way VBA in Excel 2007 interprets these two lines of code:

    Xnode1 = Xleft + (mySrs1.XValues(Ipts) - Xmin) * Xwidth / (Xmax - Xmin)
    Ynode1 = Ytop + (Ymax - mySrs1.Values(Ipts)) * Yheight / (Ymax - Ymin)
 

These lines provide the X and Y coordinates of the point in the first series (the tail of the arrow), in pixels from the top left of the chart. MySrs1.Values(Ipts) correctly returns the Y value of the point, but MySrs1.XValues(Ipts) returns not the X value of the point, but the index of the point in the series, as text, not as a numeric value.

In the chart below, I have highlighted the sixth point in each series and the sixth arrow. We can see that the arrow points from the Y value of point 6 in the first series down to the Y value of point 6 in the second series, while the X value of both endpoints of the arrow is 6.

I can think of another way to create the desired arrows in Excel 2007, and when I have a chance I will write them up.

Stay tuned.

Update 3 June 2009

I discovered that if a chart only has one series, the lines of code above will return the correct X value, though it is still typed as a String.

Update 4 June 2009

On the suggestion of Andy Pope, I downloaded and installed SP2 (I had been using Excel 2007 SP1). As Andy indicates, the code from my earlier article runs fine. The proper X values are extracted from the series data, and they are even typed as doubles.

SP2 fixes the problem. Good job with the update, and sorry to have reported a problem that was already fixed.

I did find another bug, however. I wrote a little routine to spit out chart data into the worksheet, and I used

 With ActiveChart.Parent.TopLeftCell.Offset(, 9)
 

to locate the output of the routine. This works fine in Excel 2003. Excel 2007 SP2 chokes on the Offset method of the Range object, and the line above is highlighted in the debugger.

This works in 2003

 Dim rTopLeft As Range
 Set rTopLeft = ActiveChart.Parent.TopLeftCell
 With rTopLeft.Offset(, 9)
 

but the last line of the above still chokes on Offset. What finally works in 2007 is

With Range(ActiveChart.Parent.TopLeftCell.Address).Offset(, 9)
 

A little work in the Immediate Window shows that it’s TopLeftCell that has the problem.

Related Posts:

Bookmark and share this entry:
  • Twitter
  • Digg
  • Facebook
  • LinkedIn
  • del.icio.us
  • Technorati
  • StumbleUpon
  • Google Bookmarks
  • Reddit
  • MySpace
  • Slashdot
  • Yahoo! Buzz
  • Tumblr

Learn how to create Excel dashboards.

Comments


Comment from Andy Pope
Time: Thursday, June 4, 2009, 3:05 am

Hi Jon,

I just tried the code with SP2 and it works as expected. You still got SP1?


Comment from Jon Peltier
Time: Thursday, June 4, 2009, 5:43 am

Andy -

Yep, I’m using SP1. I’ve heard some horror stories about the upgrade, so I’ve been putting it off. (I only upgraded to Windows XP SP3 last week.)

I did find out that if there is a single series in the chart, the values came out fine, although they were still considered Strings, instead of Doubles as in 2003.

I’ll upgrade to SP2, and correct the article if necessary.


Comment from Jon Peltier
Time: Thursday, June 4, 2009, 9:49 am

Andy -

SP2 has corrected the problem with extracting X values from the series.

But in the process of testing this, I uncovered another problem.

I’ve updated the post to reflect both of these events.


Comment from Andy Pope
Time: Thursday, June 4, 2009, 10:07 am

Oh the joys of the ‘07 OM.

It’s one step forward, 2 hops back!

Write a comment

I welcome comments from my readers. If you have an opinion on this post, if you have a question or if there is anything to add, I want to hear from you. Whether you agree or disagree, please join the discussion.

If you want to include an image in your comment, post it on your own site or on one of the many free image sharing sites, and include a link in your comment. I'll download your image and insert the necessary html to display the image inline.

Read the PTS Blog Comment Policy.





Subscribe without commenting

Peltier Tech Waterfall Chart Utility Peltier Tech Cluster-Stack Chart Utility Peltier Tech Box and Whisker Chart Utility Peltier Tech Marimekko Chart Utility Peltier Tech Dot Plot Utility Peltier Tech Cascade Chart Utility

Create Excel dashboards quickly with Plug-N-Play reports.