I am creating several charts and I get an error when I try to add a title to some graphs.
The first 4 graphs are executed perfectly, but when I got to the fifth, I get an error on the line which adds the title:
"This object has no title"
Does anyone know why this happens on that particular graph (and all others after it). I used the same line in previous charts and it worked just fine.
Thanks!!
Code:
'Graph
With Sheet1.ChartObjects.Add(Left:=390, Width:=375, Top:=10, Height:=225)
.Chart.SetSourceData Source:=Sheet22.Range("A1:R2")
.Chart.ChartType = xlColumnClustered
.Chart.ChartTitle.Characters.Text = "SC1 Downtime " & StartDate & "-" & EndDate
.Chart.SetElement (msoElementPrimaryValueAxisTitleRotated)
.Chart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Total Hours"
End With
With Sheet1.ChartObjects.Add(Left:=775, Width:=375, Top:=10, Height:=225)
.Chart.SetSourceData Source:=Sheet22.Range("A3:R4")
.Chart.ChartType = xlColumnClustered
.Chart.ChartTitle.Characters.Text = "SC2 Downtime " & StartDate & "-" & EndDate
.Chart.SetElement (msoElementPrimaryValueAxisTitleRotated)
.Chart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Total Hours"
End With
With Sheet1.ChartObjects.Add(Left:=390, Width:=375, Top:=245, Height:=225)
.Chart.SetSourceData Source:=Sheet22.Range("A5:R6")
.Chart.ChartType = xlColumnClustered
.Chart.ChartTitle.Characters.Text = "SC5 Downtime " & StartDate & "-" & EndDate
.Chart.SetElement (msoElementPrimaryValueAxisTitleRotated)
.Chart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Total Hours"
End With
With Sheet1.ChartObjects.Add(Left:=775, Width:=375, Top:=245, Height:=225)
.Chart.SetSourceData Source:=Sheet22.Range("A7:R8")
.Chart.ChartType = xlColumnClustered
.Chart.ChartTitle.Characters.Text = "SC4 Downtime " & StartDate & "-" & EndDate
.Chart.SetElement (msoElementPrimaryValueAxisTitleRotated)
.Chart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Total Hours"
End With
'Graph Line
With Sheet1.ChartObjects.Add(Left:=390, Width:=375, Top:=480, Height:=225)
.Chart.SetSourceData Source:=Sheet8.Range("T" & iStart & ":T" & iEnd)
.Chart.ChartType = xlLineMarkers
.Chart.ChartTitle.Characters.Text = "SC1 " & StartDate & "-" & EndDate
.Chart.SeriesCollection(1).XValues = Sheet8.Range("B" & iStart & ":B" & iEnd)
.Chart.Axes(xlCategory).CategoryType = xlCategoryScale
.Chart.SetElement (msoElementPrimaryValueAxisTitleRotated)
.Chart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Inch2/min"
End With
With Sheet1.ChartObjects.Add(Left:=775, Width:=375, Top:=480, Height:=225)
.Chart.SetSourceData Source:=Sheet9.Range("T" & iStart & ":T" & iEnd)
.Chart.ChartType = xlLineMarkers
.Chart.ChartTitle.Characters.Text = "SC2 " & StartDate & "-" & EndDate
.Chart.SeriesCollection(1).XValues = Sheet9.Range("B" & iStart & ":B" & iEnd)
.Chart.Axes(xlCategory).CategoryType = xlCategoryScale
.Chart.SetElement (msoElementPrimaryValueAxisTitleRotated)
.Chart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Inch2/min"
End With
With Sheet1.ChartObjects.Add(Left:=390, Width:=375, Top:=515, Height:=225)
.Chart.SetSourceData Source:=Sheet10.Range("T" & iStart & ":T" & iEnd)
.Chart.ChartType = xlLineMarkers
.Chart.ChartTitle.Characters.Text = "SC5 " & StartDate & "-" & EndDate
.Chart.SeriesCollection(1).XValues = Sheet10.Range("B" & iStart & ":B" & iEnd)
.Chart.Axes(xlCategory).CategoryType = xlCategoryScale
.Chart.SetElement (msoElementPrimaryValueAxisTitleRotated)
.Chart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Inch2/min"
End With
With Sheet1.ChartObjects.Add(Left:=775, Width:=375, Top:=515, Height:=225)
.Chart.SetSourceData Source:=Sheet11.Range("T" & iStart & ":T" & iEnd)
.Chart.ChartType = xlLineMarkers
.HasTitle = True
.Chart.ChartTitle.Characters.Text = "SC4 " & StartDate & "-" & EndDate
.Chart.SeriesCollection(1).XValues = Sheet11.Range("B" & iStart & ":B" & iEnd)
.Chart.Axes(xlCategory).CategoryType = xlCategoryScale
.Chart.SetElement (msoElementPrimaryValueAxisTitleRotated)
.Chart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Inch2/min"
End With
"This object has no title"
Does anyone know why this happens on that particular graph (and all others after it). I used the same line in previous charts and it worked just fine.
Thanks!!