I need charts in a Sheet taking up various ranges as the data source.
It would be beneficial to have a sub that creates a chart and positions it in the Sheet. Then call it from another sub and once the chart has been created, feed it with relevant data and customise to suit.
Simplified code for the chart creating sub:
Sub Charts(s As Worksheet, x, y, z, t)
Dim ch As ChartObject
Set ch = s.ChartObjects.Add(Left:=x, Width:=y, Top:=z, Height:=t)
End Sub
I want to call it, capture the newly created chart and work on it:
Sub X()
Dim s2 as Worksheet
Set s2 = Sheets(2)
aa = s2.Range("e5").Top
bb = s2.Range("e5").Top
cc = 500
dd = 400
Call Charts(s2, aa, dd, bb, cc)
End Sub
After calling Sub Charts a chart is placed in the desired Sheet but the object has been created elsewhere.
How do I capture it from X sub and work with the chart there?
I tried creating a new chart object and accessing it.
Charts()a function (instead of aSub), that returns the chart it creates.