Found this code by Jon Peltier:
https://peltiertech.com/assign-chart...ries-with-vba/
It lets you select a range that contains the series name via InputBox.
Sub SelectRangeWithSeriesNames()
If ActiveChart Is Nothing Then
MsgBox "Select a chart and try again.", vbExclamation, "No Chart Selected"
Else
Dim Prompt As String
Prompt = "Select a range that contains series names for the active chart."
Dim Title As String
Title = "Select Series Names"
Dim SeriesNameRange As Range
On Error Resume Next
Set SeriesNameRange = Application.InputBox(Prompt, Title, , , , , , 8)
On Error GoTo 0
If Not SeriesNameRange Is Nothing Then
If SeriesNameRange.Rows.Count = 1 Or SeriesNameRange.Columns.Count = 1 Then
With ActiveChart
Dim iSrs As Long
For iSrs = 1 To .SeriesCollection.Count
If iSrs <= SeriesNameRange.Cells.Count Then
.SeriesCollection(iSrs).Name = _
"=" & SeriesNameRange.Cells(iSrs).Address(, , , True)
End If
Next
End With
Else
MsgBox "Select a range with one row or one column", vbExclamation, _
"Must be One Row or Column"
End If
End If
End If
End Sub
So I added these lines to my create chart code, hoping it would do. Nothing happened.
Dim SeriesNameRange As Range
Set SeriesNameRange = ("B1:C1)
What am I missing?
Thanks Jon!
Thanks everyone!
Bookmarks