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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,216,116
Messages
6,128,926
Members
449,479
Latest member
nana abanyin

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