why this charting With/End With crashes?

roc_on_the_rocks

Board Regular
Joined
Jun 6, 2009
Messages
175
Office Version
  1. 365
Platform
  1. Windows
Hello folks,

I'm trying to clean up this piece of charting code...

... from this:

Code:
'add Temperature series
    With ActiveChart
        .SeriesCollection.NewSeries
        .SeriesCollection(2).Name = y2Title
        .SeriesCollection(2).XValues = xData
        .SeriesCollection(2).Values = y2Data
        .SeriesCollection(2).Border.ColorIndex = 6
        .SeriesCollection(2).Border.Weight = xlThin
        .SeriesCollection(2).Border.LineStyle = xlContinuous
     End With

to this:

Code:
'add Temperature series
    With ActiveChart
        .SeriesCollection.NewSeries
        With [COLOR=red]SeriesCollection[/COLOR](2)
            .Name = y2Title
            .XValues = xData
            .Values = y2Data
            .Border.ColorIndex = 6
            .Border.Weight = xlThin
            .Border.LineStyle = xlContinuous
        End With
    End With

But it crashes with the error message: "Compile error: Sub or Function not defined"

Any help will be very appreciated.

Thanks!
 
Last edited:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Have you tried

with activechart.seriescollection.seriescollection(2)

and only having one with statement

I dont really know much about the charts collectionbut worth a try
 
Upvote 0
Solution

Forum statistics

Threads
1,224,521
Messages
6,179,277
Members
452,902
Latest member
Knuddeluff

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