title: Excel VBA macro to copy and paste charts works sometimes
body: <p>I wrote a macro that imports a large CSV data file, organizes the data, and creates charts. The charts are created by:</p>
  
  <ul>
  <li>Copy template chart</li>
  <li>Paste on another tab</li>
  <li>Rename chart</li>
  <li>Add data series</li>
  <li>Repeat for each column of data</li>
  </ul>
  
  <p>The problem I'm having is that when I run the macro normally, it doesn't actually copy the template chart. So there's nothing on the clipboard when it goes to paste, which throws an error. Here's the actual code:</p>
  
  <pre><code>wbGen.Sheets("Dashboard").ChartObjects("Chart 0").Activate
  ActiveChart.ChartArea.Copy
  wbGen.Sheets("Charts").Activate
  ActiveSheet.Cells(iRotor * 16 - 31, iChartA * 7 - 6).Select
  ActiveSheet.Paste 'Debug mode points to this line
  ActiveSheet.ChartObjects("Chart 0").Activate
  ActiveSheet.Shapes("Chart 0").Name = "Chart " &amp; iChart
  </code></pre>
  
  <p>Here's the rub: if I click <code>Debug</code>, back the cursor up to the first line above, and hit continue, then the code executes perfectly. I can't figure out why it works in debug mode but not normally. I appreciate any help you can provide.</p>
  
  <p>As a side note, my attempts to get rid of the <code>Activate</code> and <code>Select</code> statements haven't been fruitful. Any help I can get in that area would also be appreciated.</p>