ich möchte ein Diagramm mit VBA formatieren.
Der Grundcode stammt von Karin aka Beverly. Ich habe versucht diesen etwas zu erweitern. Zum Teil ist mir dies gelungen.
Wasjetzt nicht funktioniert ist die Formatierung für
- das Zahlenformat der Y-Achse
Ist es möglich das Zahlenformat als Textbeschreibung aus einer Zelle zu übernehmen? z. B. "#.##0,00" oder "#.##0" je nach Zellinhalt
- die Formatierung des Diagrammtitels
- die Formatierung der Diagrammfläche
- die Formatierung der Zeichnungsfläche
Könnte mir dabei bitte jemand helfen?
Vielen Dank im Voraus.
Viele Grüße
Ralf
<pre>Private Sub Worksheet_Change(ByVal Target As Range)
'durch Set ist eine Aktivierung des Diagramms nicht mehr nötig
Dim chDiagramm As Chart ' Variable für das Diagrammobjekt
'Prozedur verlassen wenn aktive Tabelle nicht Tabelle1 ist
If ActiveSheet.Name <> "Diagramm" Then Exit Sub
'Prozedur verlassen wenn keine numerischen Werte für Minimum und Maximum
If Not IsNumeric(Cells(10, 9)) Or Not IsNumeric(Cells(10, 10)) Then Exit Sub
'Prozedur verlassen wenn Maximum kleiner als Minimum
If Cells(10, 9) < Cells(10, 9) Then Exit Sub
'Falls das Diagramm aktiviert ist, zur Sprungmarke Ende gehen
On Error GoTo Ende
'Diagramm 1 der Variablen zuweisen
Set chDiagramm = Worksheets("Diagramm").ChartObjects("Diagramm 1").Chart
'Category (Y) Axis
With chDiagramm.Axes(xlValue)
.MaximumScale = Cells(10, 9)
.MinimumScale = Cells(10, 10)
.MajorUnit = Cells(10, 11)
.MinorUnit = Cells(10, 12)
.MajorTickMark = xlOutside
.MinorTickMark = xlOutside
.HasMajorGridlines = True
.HasMinorGridlines = False
'.Selection.TickLabels.NumberFormat = "#.##0,00"
End With
'Category (X) Axis
With chDiagramm.Axes(xlCategory)
.MinimumScale = Cells(6, 5)
.MaximumScale = Cells(6, 6)
.MajorUnit = "10"
.MinorUnit = "5"
.MajorTickMark = xlOutside
.MinorTickMark = xlOutside
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
'Formatierung Diagrammtitel
If chDiagramm.HasTitle = True Then
With Title.Format.TextFrame2.TextRange.Font
.Name = "Arial"
.Bold = True
.Size = 14
End With
End If
'Formatierung Legende
If chDiagramm.HasLegend = True Then
With Legend.Format.TextFrame2.TextRange.Font
.Name = "Arial"
.Size = 10
End With
End If
'Formatierung Diagrammfläche
With chDiagramm.ChartArea.Format
With .Fill
.ForeColor.RGB = RGB(255, 255, 255) 'weiß
End With
With .Line
.Visible = msoTrue
.DashStyle = msoLineSolid
.Weight = 0
.ForeColor.RGB = RGB(255, 255, 255) 'weiß
End With
End With
'Formatierung Zeichnungsfläche
With chDiagramm.PlotArea.Format
With .Fill
.Visible = msoFalse
.ForeColor.RGB = RGB(255, 255, 255) 'weiß
End With
With .Line
.Visible = msoFalse '=msoTrue wenn Linie angezeigt werden soll
.DashStyle = msoLineSolid
.Weight = 1
.ForeColor.RGB = RGB(127, 127, 127) 'weiß, Hintergrund 1, dunkler 50%
End With
End With
Ende:
' Variable leeren
Set chDiagramm = Nothing
End Sub</pre>