Interesting VBA problem.

xamination

New Member
Joined
Jul 8, 2011
Messages
5
I am writing a program which takes data from multiple charts and combines them into one singular chart. Everything seems to be working fine, until I get to these last two lines

ActiveChart.HasTitle = True
ActiveChart.ChartTitle.Text = chartName

Now, if I run the macro as is, I get an error message telling me "The object has no title." Hovering over ActiveChart.HasTitle says it is set at false. HOWEVER, if I put a stop in a few lines before, and step through these lines, everything works fine, no problem. I even put a do until loop around "activechart.hastitle = true" to make sure it was setting it to true.

It seems that if I run through it as normal it will throw an error. But if I step through it it won't. Whats causing this error, or what would be a work around at least?

Thanks in advance
 
In that case, a tip of the cap, a "welcome to the board" and a "much obliged" to Seth. It ain't many members whose first post is an answer to a question instead of a question.
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Ha! thanks, I'll try and anwser more as I come across any, hard to keep up with work and the message boards at the same time.
 
Upvote 0
The .SetElement(...) method. Still have no idea why I was getting the problem I was, but it's water under the bridge IMO

This line also fell victim to this VBA blunder.. In some sheets this worked and in others it threw the same error. But Do Until Loop solved the problem

e.g. :P (greater than 2 repeats worked for my sheet but please increase generously if yours still fails)

Code:
Dim nonsense As Integer
nonsense = 1
   
Do Until nonsense > 2
    ActiveChart.SetElement (msoElementChartTitleAboveChart)
    nonsense = nonsense + 1
Loop


ActiveChart.ChartTitle.Text = "My Chart Title"
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top