Frag mich nicht warum...
25.07.2004 20:05:59
Björn
Hallo Erich,
hallo Rainer,
damit Erich nicht immer zwei Pfade bedienen muss, antworte ich mal hier.
Warum es so ist, wie es ist, weiß ich auch nicht. Tatsache ist aber, wenn man für Xvalues und values statt "R und C" "Z und S" verwendet geht's. Ach ja ausserdem verlangt das Programm nun bei Xvalues ein "=" vor dem Blattnamen.
Eine funktionierende Lösung für meinen Vorschlag sieht somit folgendermaßen aus:
Private Sub Chart_Activate()
Dim Startjahr As Integer, zaehler_1 As Integer
Startjahr = ThisWorkbook.Sheets("Liplanpa").Cells(32, 2)
For zaehler_1 = 34 To 59
If ThisWorkbook.Sheets("Liplanpa").Cells(zaehler_1, 1) = Startjahr Then
With ActiveChart.SeriesCollection(1)
.XValues = "=Liplanpa!Z" & zaehler_1 & "S1:Z59S1"
.Values = "=Liplanpa!Z" & zaehler_1 & "S16:Z59S16"
End With
With ActiveChart.Axes(xlValue)
.MinimumScale = ThisWorkbook.Sheets("Liplanpa").Cells(62, 16)
.MaximumScale = ThisWorkbook.Sheets("Liplanpa").Cells(63, 16)
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
ActiveChart.ChartTitle.Characters.Text = "Nettozufluss kumuliert ab " & Startjahr
Exit For
End If
Next zaehler_1
End Sub
Und für Rainer's Lösung muss es nun lauten:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer
Dim tarYear As Integer, lastR As Integer, myLow As Integer, myHigh As Integer
Dim dataSrc As String, dataLab As String
Dim wks As Worksheet, diaSh As Chart
Dim kumDia As Diagramm1
If Target.Address(False, False) <> "B32" Then Exit Sub
dataSrc = ""
dataLab = ""
Set wks = Worksheets(ActiveSheet.Name)
Set diaSh = Charts(1)
tarYear = wks.Cells(32, 2)
For i = 34 To wks.Cells(65536, 1).End(xlUp).Row
If wks.Cells(i, 1) = tarYear Then
lastR = i
Exit For
End If
Next i
myLow = WorksheetFunction.Min(Range("P34", "P59")) - 1
myHigh = WorksheetFunction.Max(Range("P34", "P59")) + 1
With diaSh
.ChartTitle.Text = "Kumuliert nach " & tarYear
.SeriesCollection(1).XValues = "=Liplanpa!Z" & i & "S1:Z59S1"
.SeriesCollection(1).Values = "=Liplanpa!Z" & i & "S16:Z59S16"
End With
With diaSh.Axes(xlValue)
.MinimumScale = myLow
.MaximumScale = myHigh
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
diaSh.Select
End Sub
Warum das so ist, kann vielleicht Rainer sagen. Ich nicht.
Gruß
Björn