Reputation: 9
As the title says, the code won't find the ActiveChart
even though the line before it selects it. How can i fix it?
Sub makeChart(myArr As Variant, title As String)
Dim cht As Chart
Dim sht As Worksheet
Set sht1 = Sheets("Action Register")
sht1.Shapes.AddChart.Select
Set cht = sht.ActiveChart
With ActiveChart
.Parent.Top = Range("D20").Top 'Places chart onto specified area
.Parent.Left = Range("D20").Left
.Parent.Width = Range("D20:V20").Width
.Parent.Height = Range("D20:D29").Height
.ChartType = xlAreaStacked
.SeriesCollection.NewSeries
.SeriesCollection(1).Name = "=""Machine"""
.SeriesCollection(1).XValues = Application.Index(myArr, , 1)
.SeriesCollection(1).Values = Application.Index(myArr, , 2)
.SeriesCollection.NewSeries
.SeriesCollection(2).Name = "=""Handling"""
.SeriesCollection(2).Values = Application.Index(myArr, , 3)
.SeriesCollection.NewSeries
.SeriesCollection(3).Name = "=""Fiber"""
.SeriesCollection(3).Values = Application.Index(myArr, , 4)
.SeriesCollection.NewSeries
.SeriesCollection(4).Name = "=""Process"""
.SeriesCollection(4).Values = Application.Index(myArr, , 5)
.SeriesCollection.NewSeries
.SeriesCollection(5).Name = "=""Other"""
.SeriesCollection(5).Values = Application.Index(myArr, , 6) 'Legends and writes in values for graph
.Axes(xlCategory, xlPrimary).HasTitle = True 'Labels
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Months"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Rate(m)"
.ChartArea.Font.Size = 20
End With
End Sub
Upvotes: 1
Views: 81
Reputation: 34045
A worksheet doesn't have an ActiveChart
property. Just use ActiveChart
or Application.ActiveChart
.
Upvotes: 1
Reputation: 307
Right of the top I can see these 2 mistakes
Dim sht1 As Sheets <-------- you forgot this (not sht as Worksheet)
Set sht1 = Sheets("Action Register")
sht1.Shapes.AddChart.Select
Set cht = sht.ActiveChart <-------------- you got your naming all wrong here
Upvotes: 0