If-then statement that checks for existence of series 2

D

danz98

I would like to code an if-then or Case statement that does something like this:



If ActiveChart.SeriesCollection(2) doesn’t exist, Then



ActiveChart.SeriesCollection.NewSeries.Add

ActiveChart.SeriesCollection(2).XValues = "=Sheet1!R1C9:R2C9"

ActiveChart.SeriesCollection(2).Values = "=Sheet1!R1C10:R2C10"



Else



ActiveChart.SeriesCollection(2).XValues = "=Sheet1!R1C9:R2C9"

ActiveChart.SeriesCollection(2).Values = "=Sheet1!R1C10:R2C10"



The only difference is the NewSeries.Add. What do I substitute for doesn’t exist? 0 (zero) or False?



Danz98
 
G

Guest

Try something like:

Dim Ser2 As Series

On Error Resume Next
Set Ser2 = ActiveChart.SeriesCollection(2)
On Error GoTo 0
If Ser2 Is Nothing Then
MsgBox "doesn't exist"
Else
MsgBox "does exist"
End If

Regards
Rowan
 
D

danz98

thanks Rowan. I was able to get it to work. Much appreciated.

danz98
Try something like:

Dim Ser2 As Series

On Error Resume Next
Set Ser2 = ActiveChart.SeriesCollection(2)
On Error GoTo 0
If Ser2 Is Nothing Then
MsgBox "doesn't exist"
Else
MsgBox "does exist"
End If

Regards
Rowan
 
G

Guest

You're welcome!

danz98 said:
thanks Rowan. I was able to get it to work. Much appreciated.

danz98
Try something like:

Dim Ser2 As Series

On Error Resume Next
Set Ser2 = ActiveChart.SeriesCollection(2)
On Error GoTo 0
If Ser2 Is Nothing Then
MsgBox "doesn't exist"
Else
MsgBox "does exist"
End If

Regards
Rowan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top