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
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Pomme

New Member
Joined
Jul 20, 2010
Messages
8
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!
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,413
Messages
5,511,186
Members
408,829
Latest member
sheshe123

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top