Results 1 to 6 of 6

Error 1004 on SeriesCollection

Threaded View

  1. #1
    Registered User
    Join Date
    08-24-2010
    Location
    POZnan*,Poland
    MS-Off Ver
    Excel 2003
    Posts
    5

    Error 1004 on SeriesCollection

    Hi again,

    I wrote macro:
    Private Sub CommandButton4_Click()
    
    If Range("A2") <> "" And OptionButton1.Value Or OptionButton2.Value Then
    
    Application.ScreenUpdating = False
    
    lw = Application.WorksheetFunction.CountA(Columns(1))
    
    Charts.Add
        
        With ActiveChart
        .ChartType = xlXYScatterSmoothNoMarkers
        .SetSourceData Source:=Sheets("Dane").Range("A2:F" & lw), PlotBy:=xlColumns
        .Location Where:=xlLocationAsNewSheet
        .HasTitle = False
        .HasLegend = False
        .ChartArea.AutoScaleFont = False
        .ChartArea.Border.LineStyle = xlNone
        .PlotArea.Interior.ColorIndex = xlNone
        End With
            
        With ActiveChart.SeriesCollection(1)
        .XValues = Sheets("Dane").Range("D2:D" & lw)
        If OptionButton1.Value Then
        .Values = Sheets("Dane").Range("E2:E" & lw)
        .Name = Sheets("Dane").Range("E1")
        ElseIf OptionButton2.Value Then
        .Values = Sheets("Dane").Range("F2:F" & lw)
        .Name = Sheets("Dane").Range("F1")
        End If
        .AxisGroup = 1
        .MarkerStyle = xlNone
        .Border.ColorIndex = 1
        .Border.Weight = xlThin
        .Border.LineStyle = xlContinuous
        End With
        
    ->>>>   With ActiveChart.SeriesCollection(2)
        .XValues = Sheets("Dane").Range("D2:D" & lw)
        .Values = Sheets("Dane").Range("B2:B" & lw)
        .Name = Sheets("Dane").Range("B1")
        .AxisGroup = 2
        .MarkerStyle = xlNone
        .Border.ColorIndex = 1
        .Border.Weight = xlThin
        .Border.LineStyle = xlContinuous
        End With
        
        With ActiveChart
        .Axes(xlCategory, xlPrimary).HasTitle = True
        .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Czas"
        .Axes(xlValue, xlPrimary).HasTitle = True
        .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Masa"
        .Axes(xlValue, xlSecondary).HasTitle = True
        .Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = "Temperatura"
        .Axes(xlCategory).TickLabels.AutoScaleFont = False
        .Axes(xlCategory).AxisTitle.AutoScaleFont = False
        .Axes(xlValue).TickLabels.AutoScaleFont = False
        .Axes(xlValue).AxisTitle.AutoScaleFont = False
        End With
        
        With ActiveChart.Axes(xlCategory).TickLabels.Font
            .Name = "Arial"
            .FontStyle = "Pogrubiony"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
            .Background = xlAutomatic
        End With
        With ActiveChart.Axes(xlValue, xlPrimary).TickLabels.Font
            .Name = "Arial"
            .FontStyle = "Pogrubiony"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
            .Background = xlAutomatic
        End With
        With ActiveChart.Axes(xlValue, xlSecondary).TickLabels.Font
            .Name = "Arial"
            .FontStyle = "Pogrubiony"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
            .Background = xlAutomatic
        End With
        With ActiveChart.Axes(xlCategory).AxisTitle.Font
            .Name = "Arial"
            .FontStyle = "Pogrubiony"
            .Size = 16
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
            .Background = xlAutomatic
        End With
        With ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Font
            .Name = "Arial"
            .FontStyle = "Pogrubiony"
            .Size = 16
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
            .Background = xlAutomatic
        End With
        With ActiveChart.Axes(xlValue, xlSecondary).AxisTitle.Font
            .Name = "Arial"
            .FontStyle = "Pogrubiony"
            .Size = 16
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
            .Background = xlAutomatic
        End With
        With ActiveChart.Axes(xlCategory)
            .MinimumScale = 0
            .MaximumScale = 380
            .MinorUnit = 30
            .MajorUnit = 60
            .Crosses = xlCustom
            .CrossesAt = 0
            .ReversePlotOrder = False
            .ScaleType = xlLinear
            .DisplayUnit = xlNone
        End With
        With ActiveChart.Axes(xlValue)
            .MinimumScale = 0
            .MaximumScaleIsAuto = True
            .MinorUnitIsAuto = True
            .MajorUnitIsAuto = True
            .Crosses = xlCustom
            .CrossesAt = 0
            .ReversePlotOrder = False
            .ScaleType = xlLinear
            .DisplayUnit = xlNone
        End With
        With ActiveChart.Axes(xlValue, xlSecondary)
            .MinimumScale = 10
            .MaximumScale = 90
            .MinorUnit = 5
            .MajorUnit = 10
            .Crosses = xlCustom
            .CrossesAt = 0
            .ReversePlotOrder = False
            .ScaleType = xlLinear
            .DisplayUnit = xlNone
        End With
    Application.ScreenUpdating = True
    
    Else
    
    MsgBox "Brakuje danych do kreślenia, bądź nie wybrano typu wykresu!", vbCritical, "Błąd"
    Exit Sub
    End If
    
    End Sub
    But it doesn't work because of run-time error 1004 : 'method "series collection" of object "_chart" failed' (on marked by ->>>> line). Any idea why?

    I have just noticed that problem is in col. B because it`s imported from txt files not enter manually to sheet but still can't find solution.
    Attached Files Attached Files
    Last edited by d_omin; 08-27-2010 at 05:49 AM.
    Best regards,
    d_omin
    'Part of the inhumanity of the computer is that, once it is competently programmed and working smoothly, it is completely honest...' (Isaac Asimov)

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