我最终想到了一个有点迂回的解决方法;这是任何有兴趣的人的代码,适合我原始问题的布局:
Sub Example()
' Variable Definitions
Dim y As Integer
Dim Name(73) As String
Dim Mins(73) As Integer
Dim Maxs(73) As Integer
' Loop Through Name Column (Series)
For Each x In Range("A4:A" & Cells(Rows.Count, "A").End(xlUp).Row)
' Add Values to Arrays, If Not Preexisting
If IsInArray(x.Value(), Name) = False Then
Name(y) = x.Value()
Mins(y) = x.Row()
Maxs(y) = x.Row()
y = y + 1
Else
Maxs(y - 1) = x.Row()
End If
Next x
' Add to Chart
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(1).Name = Name(0)
ActiveChart.FullSeriesCollection(1).XValues = "=Data!$B$" & Mins(0) & ":$B$" & Maxs(0)
ActiveChart.FullSeriesCollection(1).Values = "=Data!$C$" & Mins(0) & ":$C$" & Maxs(0)
End Sub
' Array Function from @JimmyPena
' http://stackoverflow.com/a/11112305/2141501
Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean
IsInArray = (UBound(Filter(arr, stringToBeFound)) > -1)
End Function