Anzeige
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

VBA: Makro in Excel 2000 --> 2003 = error

Forumthread: VBA: Makro in Excel 2000 --> 2003 = error

VBA: Makro in Excel 2000 --> 2003 = error
10.12.2006 11:03:01
Matthias
Hallo VBA-Experten!
Ich habe ein Problem: Ich möchte in einem separaten Excelblatt ein Diagramm erstellen mittels VBA. Den Code habe ich in Excel 2000 (10.0) geschrieben, da funktionierte er auch einwandfrei! Nun, wenn ich dasselbe in Excel 2003 ausführen bricht VBA ab - meistens beim Punkt "SetSourceData" etc.
Das Diagramm wird anschliessend gespeichert und in einer Userform zurückgegeben.
hier der Code (der unter Excel 2000 einwandfrei funktioniert):

Sub Grafik1()
Sheets("Tabelle3").Select
Charts.Add
ActiveChart.ChartType = xlPie
ActiveChart.SetSourceData Source:=Sheets("Tabelle3").Range("B2:B" & Sheets("Kategorien").Range("J42") + 1), PlotBy _
:=xlColumns
ActiveChart.SeriesCollection(1).XValues = "=Tabelle3!R2C1:R" & Sheets("Kategorien").Range("J42") + 1 & "C1"
ActiveChart.Location Where:=xlLocationAsObject, Name:="Tabelle3"
ActiveChart.PlotArea.Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlNone
End With
Selection.Interior.ColorIndex = xlNone
ActiveChart.ChartArea.Select
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = Range("B1")
End With
ActiveChart.SeriesCollection(1).ApplyDataLabels AutoText:=True, LegendKey:= _
False, HasLeaderLines:=False, ShowSeriesName:=False, ShowCategoryName:= _
False, ShowValue:=True, ShowPercentage:=False, ShowBubbleSize:=False
With ActiveChart.ChartGroups(1)
.VaryByCategories = True
.FirstSliceAngle = 270
End With
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.AutoScaleFont = True
With Selection.Font
.Name = "Arial"
.FontStyle = "Standard"
.Size = 8
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
ActiveChart.SeriesCollection(1).DataLabels.Select
Selection.AutoScaleFont = True
With Selection.Font
.Name = "Arial"
.FontStyle = "Standard"
.Size = 8
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
ActiveChart.ChartTitle.Select
Selection.AutoScaleFont = True
With Selection.Font
.Name = "Arial"
.FontStyle = "Fett"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
Selection.Left = 68
Selection.Top = 6
If Sheets("Kategorien").Range("J36") = "y" Then          'HIER WIRD DAS DIAGRAMM IN EINER USERFORM ANGEZEIGT!
Grafik.Info.Caption = "Saldo : " & Sheets("Auswertung").Range("K1")
Else
Grafik.Info.Caption = "Saldo : " & Sheets("Auswertung").Range("J1")
End If
If Sheets("Auswertung").Range("L1") = "r" Then
Grafik.Info.ForeColor = RGB(252, 0, 0)
Else
Grafik.Info.ForeColor = RGB(49, 101, 24)
End If
Grafik.Period.Caption = Sheets("Auswertung").Range("M1")
Grafik.Show 'vbModeless
End Sub

Besten Dank allen, die mir weiterhelfen können!
Gruss Matthias
Anzeige

1
Beitrag zum Forumthread
Beitrag zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: VBA: Makro in Excel 2000 --> 2003 = error
10.12.2006 12:27:50
ramses
Hallo
Aus der Hüfte heraus würde ich sagen, dass DIESER Code nirgends läuft, weil die schliessende Klammer nicht eingebunden ist.
ActiveChart.SetSourceData Source:=Sheets("Tabelle3").Range("B2:B" & Sheets("Kategorien").Range("J42") + 1), PlotBy _
:=xlColumns
müsste mindestens lauten
ActiveChart.SetSourceData Source:=Sheets("Tabelle3").Range("B2:B" & Sheets("Kategorien").Range("J42") + 1 & ")", PlotBy _
:=xlColumns
Aber zur Sicherheit ersetze mal
ActiveChart.SetSourceData Source:=Sheets("Tabelle3").Range("B2:B" & Sheets("Kategorien").Range("J42") + 1), PlotBy _
:=xlColumns
mit
srcString = "=Sheets(""Tabelle3"").Range(""B2:B" & Sheets("Tabelle1").Range("J42") + 1 & """)"
ActiveChart.SetSourceData Source: =srcString , PlotBy _
:=xlColumns
Gruss Rainer
Anzeige
;

Forumthreads zu verwandten Themen

Anzeige
Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige