AJP Excel Information AJP Excel Information

VBA code to delete automatic chart title when plotting single series in xl2007

Here is code and an example workbook on how to work around the deletion of the automatic chart title added when plotting a single series chart via code.

When the code inserts the chartobject and adds a single series Excel automatically uses the new series name as the chart title. Removal of the title should simply be a case of setting the HasTitle property to False. But there is a timing issue when running code and the setting to False is not applied. If you step through the code then the property is set correctly.

Simply by forcing the chart title on you can then delete it with the standard code.
Sub CreateChart()

Dim chtTemp As Chart
Dim serTemp As Series

' Add chart.
Set chtTemp = ActiveSheet.ChartObjects.Add(150, 50, 300, 250).Chart
' Add series to chart.
Set serTemp = chtTemp.SeriesCollection.NewSeries
serTemp.Name = "Data Series"
serTemp.Values = Range("B2:B5")
serTemp.XValues = Range("A2:A5")

' force chart title on so the following removal works
chtTemp.HasTitle = True
' remove default chart title
chtTemp.HasTitle = False

End Sub
VBA Remove automatic chart title code (15kb)
Created 1st May 2010
Last updated 5th August 2014 


Return to main page Chart Section VBA section Fun and games section Forum files Tips section Links section Book section Site information Site Search RSS feed Top of page


Microsoft® and Microsoft® Excel are registered trademarks of the Microsoft Corporation.
andypope.info is not associated with Microsoft. Copyright ©2007-2014 Andy Pope