I wrote a macro that imports a large CSV data file, organizes the data, and creates charts. The charts are created by:
- Copy template chart
- Paste on another tab
- Rename chart
- Add data series
- Repeat for each column of data
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:
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 " & iChart
Here's the rub: if I click Debug
, 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.
As a side note, my attempts to get rid of the Activate
and Select
statements haven't been fruitful. Any help I can get in that area would also be appreciated.