+ Reply to Thread
Results 1 to 4 of 4

Automation error when creating graphs

Hybrid View

  1. #1
    Registered User
    Join Date
    02-06-2008
    Location
    Boston
    Posts
    6

    Automation error when creating graphs

    Hey I get this automation error when I try to create line charts with three series from a array of ranges. The runtime error is -2147221080

    This only happens when I try to create the charts as an object in a worksheet. My macro works fine when creating new sheets.

    My chart creation code looks like this

    Do While i <= ChartCnt
            
            Charts.Add
            With ActiveChart
                .ChartType = xlLineMarkers
                
                Do Until .SeriesCollection.count = 0
                    .SeriesCollection(1).Delete
                Loop
                
                .SeriesCollection.NewSeries
                .SeriesCollection.NewSeries
                .SeriesCollection.NewSeries
                .SeriesCollection(1).XValues = XRng(i)
                .SeriesCollection(1).Values = VErrRng(i)
                .SeriesCollection(1).Name = "=""Validation"""
                .SeriesCollection(2).XValues = XRng(i)
                .SeriesCollection(2).Values = TErrRng(i)
                .SeriesCollection(2).Name = "=""Training"""
                .SeriesCollection(3).XValues = XRng(i)
                .SeriesCollection(3).Values = ExpRng(i)
                .SeriesCollection(3).Name = "=""Exposures"""
               
                .Location Where:=xlLocationAsObject, Name:="AvP Charts"
                '.Location xlLocationAsNewSheet, VarName(i)
                .HasTitle = True
                .ChartTitle.Text = VarName(i)
                
                .Axes(xlValue).HasMajorGridlines = True
                .PlotArea.Interior.ColorIndex = xlNone
                .SeriesCollection(3).ChartType = xlColumnClustered
                .Legend.Position = xlLegendPositionBottom
                
                .HasAxis(xlValue, xlPrimary) = True
                .HasAxis(xlValue, xlSecondary) = True
                .Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
                .Axes(xlCategory, xlSecondary).CategoryType = xlAutomatic
            
                .ChartGroups(1).Overlap = 0
                .ChartGroups(1).GapWidth = 40
                
                If YAxis(i) <> 0 Then .Axes(xlValue, xlSecondary).MaximumScale = YAxis(i)
                If i >= 1 Then .Move after:=Sheets(VarName(i - 1))
            End With
            i = i + 1
            
        Loop
    Thanks.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    Have a look at...

    HTML Code: 
    Could this be happening in your code - you appear to be working while a chart is active and not a worksheet?
    Martin

  3. #3
    Registered User
    Join Date
    02-06-2008
    Location
    Boston
    Posts
    6
    Thanks for your response. I'm reading that link right now.

  4. #4
    Registered User
    Join Date
    02-06-2008
    Location
    Boston
    Posts
    6
    I guess I had to use activeworksheet.chartobject.chart to modify the properties instead of using activechart.

+ 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