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.PlotArea.Select
ActiveChart.Axes(xlCategory).Select
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).XValues = LabelCol$ ' Excel crashes here, get ERROR 1004 message
ActiveChart.SeriesCollection(1).Select

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

End With
Ed MatsuokaPartner/Senior IT SpecialistAsked:
Who is Participating?
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.

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!
0
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

1

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("")
0
Ed MatsuokaPartner/Senior IT SpecialistAuthor Commented:
That works great, thanks!
1
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.