How do you insert the Chart Series Name by code?
Manually, this can be accomplished via "Select Data Source": select "Name", select cell(s), done.
I'd like the Series Name to be highlighted with the red frame, when the chart is selected.
Just like the Categories and Values are highlighted in purple and blue.
Tried this, doesn't work:
objChart.Chart.Name = Range("B1")
This is the create chart code:
Sub Create_Column_Chart()
Dim objChart As ChartObject
Dim myChtRange As Range
Dim myDataRange As Range
With ActiveSheet
Set myChtRange = .Range("B7:C12")
Set myDataRange = .Range("B2:C3")
Set objChart = .ChartObjects.Add( _
Left:=myChtRange.Left, Top:=myChtRange.Top, _
Width:=myChtRange.Width, Height:=myChtRange.Height)
With objChart.Chart
.ChartArea.AutoScaleFont = False
.ChartType = xlColumnClustered
.SetSourceData Source:=myDataRange
.SeriesCollection(1).Name = Range("B1")
.SeriesNameLevel = xlSeriesNameLevelCustom
' .Name = Range("B1") ' <<<<<<< causes "Run-time error '7': Out of memory"
.HasLegend = False
.HasTitle = False
.ChartArea.RoundedCorners = False
.ChartArea.Format.Line.Visible = True
.ChartArea.Format.Line.Weight = 5
.ChartArea.Format.Line.ForeColor.RGB = RGB(255, 217, 102)
.SetElement (msoElementPrimaryValueGridLinesNone)
' X-Axis
.HasAxis(xlCategory) = False
' Y-Axis
.HasAxis(xlValue) = False
End With
End With
End Sub
Thank you!
Bookmarks