Why Excel macro crashes in Excel 2010 but not in Excel 2003

Hi Experts!

I am (finally!) starting to migrate my various Excel macros to the newer versions of Office. I have an Excel macro I wrote ten years ago that plots bar charts. It works just fine under Excel 2003 but when I run the same macro using Excel 2010 it crashes on the line below:

ActiveSheet.ChartObjects("Chart 1a").Activate
ActiveChart.SeriesCollection(1).XValues = LabelCol$ ' Excel crashes here, get ERROR 1004 message

With ActiveChart.SeriesCollection(1)
.Name = ""
.Values = BrandCol$ 'X values

End With
Ed MatsuokaPartner/Senior IT SpecialistAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike in ITIT System AdministratorCommented:
Sample code/data

Can you provide the rest of the code as well? What is the value of LabelCol$? Have you tried stepping through the code? If so, do you get the expected results up until that line?
Ed MatsuokaPartner/Senior IT SpecialistAuthor Commented:
Yes, the code works just fine until it gets to that line and then it gives me the error. LabelCol$ is actually a single space, a way of making sure there is no visible label for that bar. It doesn't matter thought because when I give it a value (say A for example) it still crashes. One possible explanation is that for the new version of Excel, that value has to be a cell reference and not a string value. I replaced the LabelCol$ with ActiveSheet.Range("A36").Value (an empty cell) and it runs. I am just trying to be sure that is the real problem.

Have a great day!
Neil FlemingConsultant and developerCommented:
I think you solved your own problem. The xValues object actually expects an array. So pointing it at a range works, since the range is interpreted as an array.

You could also create a dummy array for your purposes.

ActiveChart.SeriesCollection(1).XValues = Array(0)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Neil FlemingConsultant and developerCommented:
or since you want a blank string:

ActiveChart.SeriesCollection(1).XValues = Array("")
Ed MatsuokaPartner/Senior IT SpecialistAuthor Commented:
That works great, thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.