+ Reply to Thread
Results 1 to 4 of 4

If-then statement that checks for existence of series 2

  1. #1
    danz98
    Guest

    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. #2
    Rowan
    Guest

    RE: 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) 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
    >
    >
    >


  3. #3
    danz98
    Guest

    Re: If-then statement that checks for existence of series 2

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

    danz98
    "Rowan" <Rowan@discussions.microsoft.com> wrote in message news:501DCAE2-C8DA-4D11-BEE0-5229C6843CD6@microsoft.com...
    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) 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
    >
    >
    >


  4. #4
    Rowan
    Guest

    Re: 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" <Rowan@discussions.microsoft.com> wrote in message news:501DCAE2-C8DA-4D11-BEE0-5229C6843CD6@microsoft.com...
    > 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) 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
    > >
    > >
    > >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1