Chart plotting crashes macro when used on different computers

Pomme

New Member
Joined
Jul 20, 2010
Messages
8
Hi,

I have written a program that works on my desktop computer, running a macro through all the worksheets and creating a chart on each one containg two series, on from columns A and B and the second from columns A and C, then moving onto the next spreadsheet. However, when I try to run it on my laptop it runs through the first spreadsheet fine but then crashes when it tries to plot the graph in the second one, and I can't work out why. Both computers have Excel 2007, and I have uninstalled and reinstalled the version on the laptop to check, but it still keeps coming up with this problem. I don't know if it's helpful, but I tried to plot the second graph 'manually' and it came up with the error 'Some chart types cannot be combined with different chart types. Select a different chart type'. I've included my code below.

Thanks for any help!

Code:
 Dim rngXData As Range
    Dim rngYData As Range
    Dim rngYData2 As Range
    Dim NumRows As Long
'
    Set rngXData = Range("A5", Cells(Rows.Count, 1).End(xlUp))
    Set rngYData = rngXData.Offset(0, 1)
    Set rngYData2 = rngXData.Offset(0, 2)
    
    With ActiveSheet.Shapes.AddChart.Chart
        Do While .SeriesCollection.Count > 0
            ' remove any series added automatically
            .SeriesCollection(1).Delete
        Loop
        With .SeriesCollection.NewSeries
            .Values = rngYData
            .XValues = rngXData
            .Name = "='" & ActiveSheet.Name & "'!" & rngYData.Offset(-1, 0).Cells(1, 1).Address
        End With
        
        With .SeriesCollection.NewSeries
            .Values = rngYData2
            .XValues = rngXData
            .Name = "='" & ActiveSheet.Name & "'!" & rngYData.Offset(-2, 0).Cells(2, 2).Address
        End With
        
        .ChartType = xlXYScatterSmoothNoMarkers
    End With
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi, just to let anyone who reads this thread know that the problem occurred due to the fact I was naming my spreadsheets as the name of the .txt file I was importing. Although there was no problem doing this on my desktop computer, the '.' in the name of the .txt file was causing the macro to crash when calling up an embedded chart in teh spreadsheet for some reason. Both the versions of excel were 2007 running visual basics 6.5, but the laptop used version 1020 whilst the desktop used 1053, which is the only difference I could see between the two. Hope this helps anyone else who has a similar problem!
 
Upvote 0

Forum statistics

Threads
1,222,045
Messages
6,163,583
Members
451,846
Latest member
ajk99

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