2

The code below copies a chart, selects another worksheet and if there is not already a chart, the copied chart is pasted (m=1). If there is already a chart, I want the series collection to be added to this chart.
For some reason, and I really cannot reproduce it, sometimes not the series collection is added to the existing chart but a complete chart. So, it is not a chart with two series collections but a chart in a chart. How can I fix this?


If m = 1 Then
    ActiveSheet.ChartObjects(1).Copy
    wsSummary.Select
    Cells(2, 7).Select
    ActiveSheet.Paste
    Sheets("summary").Columns(6).ColumnWidth = 2.14
    wsSolution.Select
Else:
    ActiveSheet.ChartObjects(1).Copy
    Worksheets("summary").Select
    ActiveChart.Paste
    ActiveSheet.ChartObjects(1).Activate
    wsSolution.Select
    '...
End If

Many thanks!

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Flippowitsch
  • 315
  • 3
  • 15
  • 3
    [Avoid using Select in Excel VBA](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba). Using `Select`, `Activate` and `ActiveChart` is known to have the effect that code sometimes works and sometimes not (because selection and active sheet can easily change at any point by a single mouse click or something else). So very likely this is your issue. Make your code reliable by not using them. • Note that `Else:` should be `Else` (without the colon). – Pᴇʜ Aug 02 '21 at 09:40
  • OK, thanks. I will try. – Flippowitsch Aug 02 '21 at 10:51

0 Answers0