PDA

View Full Version : naming charts



carlgren
06-21-2013, 02:17 PM
Hi,

I used the following code to create a chart:

With shtMain.ChartObjects.Add _
(Left:=20, Width:=430, Top:=170, Height:=225)
.Chart.SetSourceData source:=Sheets("Results").Range("$d$2:$e$" & rowCount)
.Chart.ChartType = xlColumn
End With

and it works fine for creating the chart but on the right hand side of the chart is "Series 1".
I can't figure out how to get rid of that or to get a title to display on my chart.


Thanks
Don

p45cal
06-21-2013, 03:44 PM
try:With shtMain.ChartObjects.Add _
(Left:=20, Width:=430, Top:=170, Height:=225)
.Chart.SetSourceData Source:=Sheets("Results").Range("$d$2:$e$" & RowCount)
.Chart.ChartType = xlColumn

.Chart.Legend.Delete
.Chart.SetElement (msoElementChartTitleCenteredOverlay)
.Chart.ChartTitle.Text = "My Title"
' With .Chart.ChartTitle.Format.TextFrame2.TextRange
' .Characters.Text = "My Title"
' With .Characters(1, 8)
' With .ParagraphFormat
' .TextDirection = msoTextDirectionLeftToRight
' .Alignment = msoAlignCenter
' End With
' With .Font
' .BaselineOffset = 0
' .Bold = msoTrue
' .NameComplexScript = "+mn-cs"
' .NameFarEast = "+mn-ea"
' .Fill.Visible = msoTrue
' .Fill.ForeColor.RGB = RGB(0, 0, 0)
' .Fill.Transparency = 0
' .Fill.Solid
' .Size = 18
' .Italic = msoFalse
' .Kerning = 12
' .Name = "+mn-lt"
' .UnderlineStyle = msoNoUnderline
' .Strike = msoNoStrike
' End With
' End With
' End With
End With
I recorded a macro, tweaked it a bit. The red lines are what you asked for. The commented-out lines where also recorded but you may find they're not needed.
I was using Excel 2010.

carlgren
06-21-2013, 03:49 PM
thanks p45cal. exactly what I was looking for!