title: VBA Chart Manipulation Slow
body: <p>I wrote some Excel VBA code that generates a scatterplot and changes a few properties of the chart. (Code is below for reference.)  The code moves slowly through tasks like deleting the chart legend, removing horizontal/vertical gridlines, and changing the X and Y series.  Excel's timer gives me the following duration for each task:</p>
  
  <pre><code>insert scatterplot: 0.01171875 
  delete series: 0 
  plot x vs y: 0.55859375 
  delete legend: 0.5703125 
  delete chart title: 0.66015625 
  remove grid: 1.3046875 
  format axes: 0 
  overall: 3.11328125
  </code></pre>
  
  <p>Removing the grid, changing the title, plotting the X and Y series, and deleting the legend seem to take a long time.  I've googled for alternative ways to write the code, but haven't been able to find anything useful.  The code works entirely as expected, except for the slow speed.  Any ideas as to what's causing the bad performance, and how I can speed this up?  Thanks in advance.</p>
  
  <p>EDIT: I've already turned off screen updating while working with the chart.  The chart is generated/formatted while a userform is open, if that makes any difference.</p>
  
  <p>Here is the relevant snippet of code:</p>
  
  <pre><code>With ActiveChart
      'Delete all series currently in plot
      Do While .FullSeriesCollection.Count &gt; 0
          .FullSeriesCollection(1).Delete
      Loop
  
      'Plot Actual (Y) vs. Inverse Distribution (X)
      .SeriesCollection.NewSeries
      .FullSeriesCollection(1).XValues = "=" &amp; tempSheetName &amp; "!$C:$C"
      .FullSeriesCollection(1).Values = "=" &amp; tempSheetName &amp; "!$A:$A"
  
      'Delete legend
      .Legend.Delete
  
      'Delete chart title
      .SetElement (msoElementChartTitleNone)
  
      'Remove gridlines
      .SetElement (msoElementPrimaryValueGridLinesNone)
      .SetElement (msoElementPrimaryCategoryGridLinesNone)
  
      'Format axes
      Dim xAxis As Axis, yAxis As Axis
      Set xAxis = .Axes(xlCategory)
      Set yAxis = .Axes(xlValue)
  
      With yAxis
          'Title y axis "actual"
          .HasTitle = True
          .AxisTitle.Caption = "Actual"
  
          'Add tick marks
          .MajorTickMark = xlOutside
      End With
  
      With xAxis
          'Title x axis by dist type
          .HasTitle = True
          .AxisTitle.Caption = dist.getDistType
  
          'Add tick marks
          .MajorTickMark = xlOutside
      End With
  End With
  </code></pre>