This thread is also posted at: http://www.mrexcel.com/forum/showthread.php?t=482127
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:'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 " & 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 " & 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 " & 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 " & 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 = "SC4 " & StartDate & "-" & EndDate 'ERROR .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 = "SC4 " & 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 = "SC4 " & 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 .ChartTitle.Text = "SC1 " & 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!!
Last edited by nbuk; 07-21-2010 at 12:50 PM. Reason: Added thread to cross post after discussing with user.
I have fixed the original problem I had yesterday, but today it seems to stop working again.
Here is the code:
Get an error at the ".chart.ChartTitle.Characters.Text...." line:With Sheet1.ChartObjects.Add(Left:=390, Width:=375, Top:=10, Height:=225) .chart.SetSourceData Source:=Sheet22.Range("A1:R2") .chart.ChartType = xlColumnClustered .chart.HasTitle = True .chart.ChartTitle.Characters.Text = "SC1 Downtime Q" & Me("Quarter").Value & " " & Me("Year").Value .chart.SetElement (msoElementPrimaryValueAxisTitleRotated) .chart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Total Minutes" .chart.Legend.Delete .chart.CopyPicture Appearance:=xlScreen, Format:=xlPicture End With
"Could not find specified object"
Any ideas on why this is happening? I have the exact code in different user forms and it runs just fine.
There is some problem with either *** Me("Quarter").Value ** or ****Me("year").Value****
The error suggests that you dont have a control by the name off Quarter or year in your user form. If it is there, then please post the spreadsheet here.
Thanks,
Vikas
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks