'Delete Method of series class failed' Error

iepritchard

Board Regular
Joined
Jan 9, 2009
Messages
52
Hi All,

I have an XY Scatter graph on a separate sheet "Chart2", and the data for this graph is on "Sheet3". I am trying to plot multiple series on the chart, but then also after making different choices deleting these series and plotting new ones. The code I have at the moment is...

Code:
Dim wsh As Worksheet
Dim serColl As SeriesCollection, ser As Series, rXValues As range
Dim lRowS As Long, lRowE As Long, lSer As Long
 
'START CHART
 
lRowE = 2 ' start in row 2  'Data starts in Cell B2 on sheet3
Set wsh = Worksheets("Sheet3")     
 
With Charts(1)
i = .SeriesCollection.Count
Do Until i < 1
.SeriesCollection(i).Delete
i = i - 1
Loop
End With 
 
'There is then some other code to delete the data from Sheet3 and replace it with the new data before plotting the new series below
 
' Add the series
    Do While wsh.range("B" & lRowE).Value <> ""  'Column B contains name of the series
        lRowS = lRowE
        Do While wsh.range("B" & lRowE + 1) = wsh.range("B" & lRowS)
            lRowE = lRowE + 1
        Loop
        Set rXValues = wsh.range(wsh.range("C" & lRowS), wsh.range("C" & lRowE)) 'column C contains the X axis data
        With serColl.NewSeries
            .XValues = rXValues
            .Values = rXValues.Offset(, 1)
            .Name = rXValues(1).Offset(, -1)
        End With
        lRowE = lRowE + 1
    Loop

Whenever I run this I get the 'Delete method of series class failed' and the .SeriesCollection(i).Delete code highlighted. I am very confused, and any help would be gratefully recieved!!

Thanks,
Ian
 
Last edited by a moderator:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,214,653
Messages
6,120,748
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top