ActiveChart Selection?

PossiblyNot

New Member
Joined
Jul 11, 2014
Messages
5
Hi all

I've been scratching my head over this problem, it seems a little odd. I have a macro that creates and automatically populates an xy chart. On startup it works, but a few minutes in to using the spreadsheet it suddenly stops working and kicks out a 91 error. sometimes it will all of a sudden start working again.

Could it be possible that there's an issue with selecting the active chart, that a few minutes in I click on a cell, or sheet or object that makes the code kick a fuss?

Code:
Sub createGraph()
   On Error GoTo ErrHandler
    'Dim xRow As Long
    'xRow = Cells(Rows.Count, "A").End(xlUp).Row
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.ChartType = xlXYScatterLinesNoMarkers
    ActiveChart.SetElement (msoElementLegendNone)                                   'Debugger sends me here. When I comment it out...
    ActiveChart.SetElement (126)                                                                    'This Errors Out
    ActiveChart.SetElement (msoElementPrimaryValueAxisTitleRotated)         'Then This
    ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Age (Ma)"              'Then This
    ActiveChart.ChartArea.Select                                                                        'You get the Pattern...
    ActiveChart.SetElement (msoElementChartTitleAboveChart)
    ActiveChart.ChartTitle.Text = "Biostratigraphy Plot"
    ActiveChart.ChartArea.Select
   
    
    With ActiveChart.Axes(xlValue)
        '.HasAxis(xlCategory) = 1
        '.HasAxis(xlSeries) = 1
        .MinimumScale = 0
        .MaximumScale = 80
        .ReversePlotOrder = True
        .DisplayUnit = xlNone
    End With

I can't quite work out what's up :/ a 91 error means I'm not Setting something somewhere, but ActiveChart can't be Set...

Cheers

Rich
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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