Microsoft Office Forum [ www.Office-Fragen.de ] >> READONLY <<

Microsoft Office 2003-2019 => Excel => Thema gestartet von: Tim1711 am August 31, 2016, 09:41:15 Vormittag

Titel: Office 2013: Diagramm mit VBA - Fehlermeldungen
Beitrag von: Tim1711 am August 31, 2016, 09:41:15 Vormittag
Hallo,

Ich möchte mittels VBA ein Diagramm erstellen und bin mittlerweile so weit gekommen:

Dim cntrclm As Integer, cntrrws As Integer
    With ThisWorkbook.Worksheets("DATASTORE")
        cntrclm = .Cells(2, Columns.count).End(xlToLeft).Column 'Method 'Columns' of object '_Global' failed
        cntrrws = .Cells(Rows.count, 1).End(xlUp).Row
    End With
   
    ThisWorkbook.Worksheets("RAM").Activate
    Charts.Add
    ActiveChart.ChartType = xlLine
    ActiveChart.SetSourceData Source:=ThisWorkbook.Worksheets("RAM").Range(Cells(3, 1), Cells(cntrrws, cntrclm)), PlotBy:=xlColumns 'Method 'Columns' of object '_Global' failed
    ActiveChart.SeriesCollection(1).Name = "Dates"      'Invalid Parameter
    ActiveChart.Location Where:=xlLocationAsObject, Name:="RAM"
    With ActiveChart
        .Parent.Name = "RAM"
        .HasTitle = True
        .ChartTitle.Characters.Text = "RAM"
        .HasLegend = True
        .Axes(xlCategory, xlPrimary).HasTitle = True
        .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time in days"
        .Axes(xlValue, xlPrimary).HasTitle = True
        .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "RAM in GB"
    End With
    ActiveSheet.Shapes("RAM").IncrementLeft -222.75
    ActiveSheet.Shapes("RAM").IncrementTop -136.5
    ActiveSheet.Shapes("RAM").ScaleWidth 1.875, msoFalse, msoScaleFromTopLeft
    ActiveSheet.Shapes("RAM").ScaleHeight 1.8211807378, msoFalse, msoScaleFromTopLeft
    ActiveChart.PlotArea.Interior.ColorIndex = xlNone
    ActiveChart.SeriesCollection(1).Values = Range(Cells(2, 2), Cells(2, cntrclm)) 'Application-defined or object-defined error
    With ActiveChart.PlotArea.Border
        .ColorIndex = 16
        .Weight = xlThin
        .LineStyle = xlContinuous
    End With


Den Code habe ich mir aus dem Internet zusammengeklaut, aber ich verstehe nicht, warum er bei mir nicht funktioniert.
Zwischenzeitlich hatte ich auch schon mehrmals debuggt, und bei der ersten Fehlermeldung im Code (With-Block) hat es bis vor kurzem keinen Error gegeben.
Bei der zweiten Fehlermeldung möchte ich den Bereich der x-Achse meines Charts definieren. Wenn ich es hier mit .Cells versuche bekomme ich "Invalid or unqualified reference" als Error.

Ich bitte um Hilfe ! Und wenn jemand helfen kann, danke ich schon einmal im Vorraus!
Titel: Antw:Office 2013: Diagramm mit VBA - Fehlermeldungen
Beitrag von: Tim1711 am August 31, 2016, 13:53:37 Nachmittag
hab meinen fehler gefunden. ich musste die zeile ThisWorkbook.Worksheets("RAM").Activate nach ganz oben setzen