Danke schon mal fürs Helfen!
Gruß
Alex
Sub TorteErstellen(target As Range)
Dim epsi As Double
Dim StrYAdr As String, rngY As Range, dataY() As Double, YValue As Double
Dim StrXAdr As String, rngX As Range, dataX(), maxItem As Long
Dim rngC As Range, maxR As Integer, maxC As Integer, c As Integer
Dim ws As Worksheet
Set ws = ActiveWorkbook.Worksheets("Tabelle1")
maxR = target.Rows.Count
maxC = target.Count / maxR
If maxR > 2 Then
MsgBox "Nur zwei Zeilen markieren X- und Y-Werte!"
Exit Sub
End If
ReDim dataX(maxC)
ReDim dataY(maxC)
epsi = 0.000000000001
maxItem = -1
StrYAdr = ""
StrXAdr = ""
For c = 1 To maxC
If IsNumeric(target.Cells(maxR, c)) Then
YValue = target.Cells(maxR, c)
If Abs(YValue) >= epsi Then
maxItem = maxItem + 1
dataY(maxItem) = YValue
StrYAdr = StrYAdr + target.Cells(maxR, c).Address + ","
StrXAdr = StrXAdr + target.Cells(1, c).Address + ","
If maxR < 2 Then
dataX(maxItem) = maxItem
Else
dataX(maxItem) = target.Cells(1, c)
End If
End If
End If
Next c
If Len(StrXAdr) > 1 Then StrXAdr = Left(StrXAdr, Len(StrXAdr) - 1)
Set rngX = ws.Range(StrXAdr)
If Len(StrYAdr) > 1 Then StrYAdr = Left(StrYAdr, Len(StrYAdr) - 1)
Set rngY = ws.Range(StrYAdr)
Charts.Add
ActiveChart.ChartType = xl3DPieExploded
ActiveChart.SetSourceData Source:=rngY, PlotBy:=xlRows
'Die folgende Zeile kann verwendet werden,
'sobald SetSourceDat mit einer beliebigen, aber gültigen
'"Initialisierungs-Range" gesetzt ist
'ActiveChart.SeriesCollection(1).YValues = dataY
ActiveChart.SeriesCollection(1).XValues = dataX
ActiveChart.Location Where:=xlLocationAsObject, Name:="Tabelle1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Testreihe ohne Leergut"
End With
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.Position = xlBottom
ActiveChart.ApplyDataLabels Type:=xlDataLabelsShowLabelAndPercent, LegendKey _
:=False, HasLeaderLines:=True
Set ws = Nothing
Set rngX = Nothing
Set rngY = Nothing
End Sub
=DATENREIHE(;(Tabelle1!$A$1;Tabelle1!$B$1;Tabelle1!$E$1);(Tabelle1!$A$2;Tabelle1!$B$2;Tabelle1!$E$2);1)