OK, I am trying to automatically add some data series to a chart using VBA. The data is found in range W148:AC158. Here is the code I have so far, but for some reason I am getting an Application-defined or object defined error on the line that has

.SeriesCollection(i).Name = Worksheets("Inputs").Cells(n, 23).Text


Here is my complete code:

Dim n As IntegerDim i As Integer


n = 148
    With ActiveChart
       
        For i = .SeriesCollection.Count To 11 Step 1
            If Sheets("Inputs").Cells(n, 25) = 0 Then
            Else
            .SeriesCollection.NewSeries
            .SeriesCollection(i).Name = Worksheets("Inputs").Range(Cells(n, 23)).Text
            .SeriesCollection(i).XValues = Worksheets("Inputs").Range(Cells(n, 28), Cells(n, 29)).Value
            .SeriesCollection(i).Values = Worksheets("Inputs").Range(Cells(n, 26), Cells(n, 27)).Value
            End If
        n = n + 1
        Next i
        
    End With
Any thoughts?