AJP Excel InformationAJP Excel Information
ChartsVBAFun stuffForumsTipsLinksBooksWhat's newContactAboutRSS Feed

 
 
 

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)
 
 
 
 
 
 
 
 
Excel tip
   

Last updated 1st May 2010

 
 
  Home | Charts | VBA Code | Fun Stuff
Forum Examples | Tips | Links | What's New | Book List
Contact | About
Microsoft® and Microsoft® Excel are registered trademarks of the Microsoft Corporation.
andypope.info is not associated with Microsoft. Copyright ©2007-20012 Andy Pope