Live-Forum - Die aktuellen Beiträge
Datum
Titel
24.04.2024 19:29:30
24.04.2024 18:49:56
Anzeige
Archiv - Navigation
1612to1616
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Problem mit Diagramm (BoxPlot)

Problem mit Diagramm (BoxPlot)
18.03.2018 15:49:33
Carlos
Hallo liebes Forum,
dies ist mein erste Frage und auch erster Post.
Meine VBA Kenntnisse sind ok, aber noch lange nicht gut.
Bisher habe ich mit dem Makro Rekorder aufgenommen und ggf. optimiert oder mit Hilfe des Internets angepasst.
Nachdem die Recherche Funktion mir hier nicht weiterhelfen konnte wollte ich euch fragen, ob ihr eine Idee zu meinen Probemen habt.
Nun zu meinem Problem:
Ich möchte mir per VBA ein Boxplot Diagramm erstellen lassen.
Dieses stellt aus einem Datensatz die Min, Max, Median, 1. und 3. Quartilwerte da.
Eigentlich habe ich mit der Diagrammerstellung keine Probleme, aber hier will es einfach nicht klappen..
Mein bisheriger Code funktioniert nur für einen einzigen Fall (angepasst vom Makrorekroder), aber sobald man diesen etwas algemeiner halten will funktioniert er schon nicht mehr und für den Median würde ich eigenltich eine Linie statt Punkt haben wollen...
Der Excel interne Diagrammtyp gefällt mir nicht sonderlich hier würde ich vorallem per VBA gerne die Füllfarbe gleich leer und den Rahmen schwarz setzen lassen.
Hier der Link zu meiner Datei mit den vollständigen Makros.
https://www.herber.de/bbs/user/120504.xlsm
Wenn jemand eine Idee/Ansatz hat, dann bitte einfach posten.
Außerdem wäre es nett, wenn jemand noch 1-2 Satz zu zB. "FullSeriesCollection" schreiben könnte. Die Hilfe war mir leider keine wirkliche Hilfe.
Viele Dank im Voraus und Grüße
Carlos

Sub Boxplot()
Worksheets("Tabelle3").Activate
Range("A4").FormulaR1C1 = "Bezeichnung"
Range("A5").FormulaR1C1 = "a"
Range("B4").FormulaR1C1 = "Oberes Quantil"
Range("B5").FormulaR1C1 = "150"
Range("C4").FormulaR1C1 = "Maximum"
Range("C5").FormulaR1C1 = "200"
Range("D4").FormulaR1C1 = "Minimum"
Range("D5").FormulaR1C1 = "100"
Range("E4").FormulaR1C1 = "Unteres Quantil"
Range("E5").FormulaR1C1 = "117"
Range("F4").FormulaR1C1 = "Median"
Range("F5").FormulaR1C1 = "133"
With Range("A4:F5")
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
ActiveChart.SetSourceData Source:=Range("Tabelle3!$A$4:$F$5")
ActiveChart.PlotBy = xlColumns
ActiveChart.ChartType = xlColumnClustered
ActiveChart.FullSeriesCollection(1).ChartType = xlColumnClustered '3.Q
ActiveChart.FullSeriesCollection(1).AxisGroup = 1
ActiveChart.FullSeriesCollection(2).ChartType = xlColumnClustered 'max
ActiveChart.FullSeriesCollection(2).AxisGroup = 1
ActiveChart.FullSeriesCollection(3).ChartType = xlColumnClustered 'min
ActiveChart.FullSeriesCollection(3).AxisGroup = 1
ActiveChart.FullSeriesCollection(4).ChartType = xlLine '1.Q
ActiveChart.FullSeriesCollection(4).AxisGroup = 1
ActiveChart.FullSeriesCollection(5).ChartType = xlLine 'med
ActiveChart.FullSeriesCollection(5).AxisGroup = 1
ActiveChart.FullSeriesCollection(1).ChartType = xlLine
ActiveChart.FullSeriesCollection(2).ChartType = xlLine
ActiveChart.FullSeriesCollection(3).ChartType = xlLine
ActiveChart.FullSeriesCollection(5).ChartType = xlXYScatter
ActiveChart.Axes(xlCategory, xlSecondary).Delete
ActiveChart.Axes(xlValue, xlSecondary).Delete
ActiveChart.FullSeriesCollection(5).Select
ActiveChart.SetElement (msoElementErrorBarStandardDeviation)
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MajorGridlines.Delete
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).HasMajorGridlines = True
ActiveChart.PlotArea.Select
Selection.Format.Fill.Visible = msoFalse
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.ChartArea.Select
Selection.Format.Line.Visible = msoFalse
With ActiveChart.Axes(xlValue).Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 255, 255)
.Solid
End With
ActiveChart.Axes(xlValue).MajorTickMark = xlInside
With ActiveChart.PlotArea.Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.349999994
End With
ActiveChart.Axes(xlValue).MajorTickMark = xlOutside
ActiveChart.FullSeriesCollection(2).Select
ActiveChart.SetElement (msoElementLineHiLoLine)
ActiveChart.Axes(xlValue).MajorGridlines.Select
With ActiveChart.ChartGroups(1)
.HasUpDownBars = True
End With
With ActiveChart.ChartGroups(1).DownBars.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 255, 255)
.Solid
End With
With ActiveChart.ChartGroups(1).HiLoLines.Format.Line
.Visible = msoTrue
.Weight = 0.5
End With
With ActiveChart.ChartGroups(1).HiLoLines.Format.Line
.Visible = msoTrue
.Weight = 0.5
End With
ActiveChart.ChartGroups(1).DownBars.Select
With Selection.Format.Line
.Visible = msoTrue
.Weight = 0.5
End With
ActiveChart.Axes(xlCategory).Select
ActiveChart.Axes(xlCategory).AxisBetweenCategories = False
ActiveChart.Axes(xlCategory).AxisBetweenCategories = True
ActiveChart.Axes(xlCategory).CrossesAt = 1
ActiveChart.Axes(xlCategory).Crosses = xlAutomatic
ActiveChart.Axes(xlCategory).TickLabelSpacing = 1
ActiveChart.Axes(xlCategory).TickLabelSpacingIsAuto = True
'    ActiveChart.PlotArea.Select
'    ActiveChart.ChartArea.Select
'    ActiveChart.Axes(xlCategory).Select
ActiveChart.Axes(xlValue).MajorGridlines.Delete
With ActiveChart.Axes(xlValue).Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(166, 166, 166)
End With
ActiveChart.Axes(xlValue).MajorTickMark = xlOutside
ActiveChart.PlotArea.Select
Selection.ClearFormats
With ActiveChart.Axes(xlValue, xlPrimary)  'y-Achse
.MinimumScale = Range("D5")
.MaximumScale = Range("C5")
End With
End Sub


		

6
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
Unklare Fragestellung
18.03.2018 15:57:55
Beverly
Hi,
was verstehst du unter: "Mein bisheriger Code funktioniert nur für einen einzigen Fall (angepasst vom Makrorekroder), aber sobald man diesen etwas algemeiner halten will funktioniert er schon nicht mehr und für den Median würde ich eigenltich eine Linie statt Punkt haben wollen..."?


AW: Unklare Fragestellung
18.03.2018 16:26:19
Carlos
Hallo Beverly,
vielen Dank für deine Rückmeldung.
Also wenn du den vom ersten Post angehängten Code ausführst solltest du sehen können was ich meine zumal es auch in der angehängten Excel Datei vorhanden ist.
Aber ich schreibe es gerne nochmal hier auf:
Der Code setzt in ganz konkrete Zellen (zB. A1="bla") die Werte (min, max etc.) ein und erstellt erfolgreich das dazugehrige Diagramm, aber wenn ich das allgemeiner halten will im Sinne, dass ich den Zellbereich frei auswählen kann (Set Bereich= oder per Schleife später) klappt es leider nicht mehr und das Diagramm kann nicht erstellt werden bzw. wird nicht so erstellt, wie es sein sollte.
Das Diagramm sollte in etwa wie auf dem Blatt 3 der Datei aussehen. Wobei das Design erstmal zweitrangig ist.
Mein Ziel ist es den Code allgemeiner zu schreiben, um es dann ggf. per Schleife zu verarbeiten, wobei das jetzt nicht wichtig ist. Der Aufbau würde dann bei der Verallgemeinerung natürlich nach dem gleichen Schema sein.
Hoffentlich ist es dir jetzt etwas verständlicher. Falls nicht kannst du gerne nochmal nachfragen.
Grüße
Carlos
Anzeige
Weiterhin unklare Fragestellung
18.03.2018 16:34:58
Beverly
Hi Carlos,
damit wird deine Fragestellung nicht klarer. Poste doch mal den Code der NICHT funktioniert...


AW: Weiterhin unklare Fragestellung
18.03.2018 17:24:55
Carlos
Hallo Beverly,
nochmal Danke für deine Rückmeldung.
Hab vergessen gehabt zu erwähnen, dass der nicht funktionsfähige Code in dem Modul 2 unter 'Sub' Boxplot_2_Versuch eingefügt ist.
Bitte entschuldige.
Da er noch nicht zu 100% funktionsfähig ist, ist er noch nicht ganz sauber formatiert.
Viele Grüße und Danke für deine Hilfe
Carlos
Sub Boxplot_2_Versuch()
Worksheets("Tabelle1").Activate
With Range("B11:G12")
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
ActiveChart.SetSourceData Source:=Range("Tabelle1!$B$11:$G$12")
ActiveChart.PlotBy = xlColumns
ActiveChart.ChartType = xlColumnClustered
ActiveChart.FullSeriesCollection(1).ChartType = xlColumnClustered '3.Q
ActiveChart.FullSeriesCollection(1).AxisGroup = 1
ActiveChart.FullSeriesCollection(2).ChartType = xlColumnClustered 'max
ActiveChart.FullSeriesCollection(2).AxisGroup = 1
ActiveChart.FullSeriesCollection(3).ChartType = xlColumnClustered 'min
ActiveChart.FullSeriesCollection(3).AxisGroup = 1
ActiveChart.FullSeriesCollection(4).ChartType = xlLine '1.Q
ActiveChart.FullSeriesCollection(4).AxisGroup = 1
ActiveChart.FullSeriesCollection(5).ChartType = xlLine 'med
ActiveChart.FullSeriesCollection(5).AxisGroup = 1
ActiveChart.FullSeriesCollection(1).ChartType = xlLine
ActiveChart.FullSeriesCollection(2).ChartType = xlLine
ActiveChart.FullSeriesCollection(3).ChartType = xlLine
ActiveChart.FullSeriesCollection(5).ChartType = xlXYScatter
ActiveChart.Axes(xlCategory, xlSecondary).Delete
ActiveChart.Axes(xlValue, xlSecondary).Delete
ActiveChart.FullSeriesCollection(5).Select
ActiveChart.SetElement (msoElementErrorBarStandardDeviation)
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MajorGridlines.Delete
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).HasMajorGridlines = True
ActiveChart.PlotArea.Select
Selection.Format.Fill.Visible = msoFalse
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.ChartArea.Select
Selection.Format.Line.Visible = msoFalse
ActiveChart.Axes(xlValue).Select
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 255, 255)
.Solid
End With
ActiveChart.Axes(xlValue).MajorTickMark = xlInside
With ActiveChart.PlotArea.Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.349999994
End With
ActiveChart.Axes(xlValue).MajorTickMark = xlOutside
ActiveChart.FullSeriesCollection(2).Select
ActiveChart.SetElement (msoElementLineHiLoLine)
ActiveChart.Axes(xlValue).MajorGridlines.Select
With ActiveChart.ChartGroups(1)
.HasUpDownBars = True
End With
With ActiveChart.ChartGroups(1).DownBars.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 255, 255)
.Solid
End With
With ActiveChart.ChartGroups(1).HiLoLines.Format.Line
.Visible = msoTrue
.Weight = 0.5
End With
With ActiveChart.ChartGroups(1).HiLoLines.Format.Line
.Visible = msoTrue
.Weight = 0.5
End With
With ActiveChart.ChartGroups(1).DownBars.Format.Line
.Visible = msoTrue
.Weight = 0.5
End With
ActiveChart.Axes(xlCategory).Select
ActiveChart.Axes(xlCategory).AxisBetweenCategories = False
ActiveChart.Axes(xlCategory).AxisBetweenCategories = True
ActiveChart.Axes(xlCategory).CrossesAt = 1
ActiveChart.Axes(xlCategory).Crosses = xlAutomatic
ActiveChart.Axes(xlCategory).TickLabelSpacing = 1
ActiveChart.Axes(xlCategory).TickLabelSpacingIsAuto = True
ActiveChart.PlotArea.Select
ActiveChart.ChartArea.Select
'    ActiveChart.Axes(xlCategory).Select
ActiveChart.Axes(xlValue).MajorGridlines.Delete
With ActiveChart.Axes(xlValue).Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(166, 166, 166)
End With
ActiveChart.Axes(xlValue).MajorTickMark = xlOutside
ActiveChart.PlotArea.ClearFormats
With ActiveChart.Axes(xlValue, xlPrimary)  'y-Achse
.MinimumScale = Range("C12")
.MaximumScale = Range("G12")
End With
End Sub

Anzeige
Die Ursache für falsches Ergebnis...
18.03.2018 17:53:03
Beverly
Hi Carlos,
...liegt darin begründet, dass deine beiden Werte-Tabellen unterschiedlich aufgebaut sind, siehe unten (obere Werte-Tabelle aus Tabelle1 "falsch" im Vergleich zur unteren aus Tabelle3):

Tabelle1
 BCDEFG
11BezeichnungMin1.QuartilMedian3. QuartilMax
12a156172,5190196,75215
13      
14BezeichnungOberes QuantilMaximumMinimumUnteres QuantilMedian
15a150200100117133
Excel-Inn.de
Hajo-Excel.de
XHTML-Tabelle zur Darstellung in Foren, einschl. der neuen Funktionen ab Version 2007
Add-In-Version 25.14 einschl. 64 Bit


Du müsstest also entweder deine Wertetabelle in Tabelle1 genau so aufbauen wie die in Tabelle3, oder du musst jede Datenreihe einzeln hinzufügen und nicht den gesamten Bereich dem Diagramm als Source zuweisen. Beim Hinzufügen jeder einzelnen Datenreihe musst du das in der Reihenfolge tun, wie die Überschriften in der Wertetabelle aus Tabelle3 aufgelistet sind.


Anzeige
AW: Die Ursache für falsches Ergebnis...
18.03.2018 18:11:00
Carlos
Hallo Beverly,
vielen Dank für dein Feedback.
Stimmt, hab nicht mehr daran gedacht als ich die ganzen Zeilen durchgegangen bin.
Vorallem dein letzter Satz ist sehr interessant für mich.
"Beim Hinzufügen jeder einzelnen Datenreihe musst du das in der Reihenfolge tun, wie die Überschriften in der Wertetabelle aus Tabelle3 aufgelistet sind."
Werde ich später ausprobieren.
Vielen Dank und einen schönen Sonntag noch
Carlos

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige