I'm running a code that requires me to name a chart so I can refer back to it later. The code I use for this is:
Sheets("Summary").Activate
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterLines
With ActiveChart
.Name = "energy distribution chart"
End With
I've tried just naming the chart not using the with... as in:
ActiveChart.Name = "energy distribution chart"
Doesn't work also. Whenever the code runs at that line I get a "run-time error 7 - Out of memory". I've tried putting this code so that it starts to run in a new macro in a new module but it still always gets that error 7 - 3 lines into a new piece of code! I have no idea what's going on. Help?
Edit: Following to mehow's answer, how do I then re-select the chart?
I've tried:
With Worksheets("Summary").ChartObjects("energy distribution chart").Chart(1)
.SeriesCollection(sheet_number - 1).XValues = Worksheets(sheet_number).Range(Sheets(sheet_number).Cells(1, 7), Sheets(sheet_number).Cells(i4, 7))
.SeriesCollection(sheet_number - 1).Values = Worksheets(sheet_number).Range(Sheets(sheet_number).Cells(1, 8), Sheets(sheet_number).Cells(i4, 8))
End With
Which doesn't seem to work... .. hm. I've also tried getting rid of the (1) next to charts. Yep. No idea.