Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default If-then statement that checks for existence of series 2



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



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default If-then statement that checks for existence of series 2

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

"danz98" wrote:



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



If ActiveChart.SeriesCollection(2) doesnt 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 doesnt exist? 0 (zero) or False?



Danz98



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default If-then statement that checks for existence of series 2

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

danz98
"Rowan" wrote in message ...
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

"danz98" wrote:



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



If ActiveChart.SeriesCollection(2) doesnt 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 doesnt exist? 0 (zero) or False?



Danz98



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default If-then statement that checks for existence of series 2

You're welcome!

"danz98" wrote:

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

danz98
"Rowan" wrote in message ...
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

"danz98" wrote:



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



If ActiveChart.SeriesCollection(2) doesnt 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 doesnt exist? 0 (zero) or False?



Danz98



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
co existence assaf1978 Excel Discussion (Misc queries) 2 December 23rd 08 12:38 PM
False if statement in series results in zero value in chart GoingBonkers Charts and Charting in Excel 2 February 13th 07 06:50 PM
COUNTIF statement with 3 criteria checks Malvaro Excel Discussion (Misc queries) 4 June 4th 06 11:40 PM
if-then statement that checks for existence of series 2 danz98 Charts and Charting in Excel 2 August 24th 05 09:20 PM
Could we define series variables in one statement? Together[_7_] Excel Programming 1 March 1st 04 07:04 AM


All times are GMT +1. The time now is 11:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"