Guten Morgen zusammen
Ich möchte bitte ein Diagramm mit einer Datenserie farben basierend auf Zellenfarbe mit VBA-Code.
Danke für Ihre Hilfe
Sub Equilibrium_curve()
Dim Chart3 As Chart ' Variable für Diagramm als Objekt
Dim CHT_3 As ChartObject
Dim rngChart_3 As Range
Dim destinationSheet_3 As String
Dim Lastrow, i As Long
Application.ScreenUpdating = False ' Bildschirmaktualisierung ausschalten
' Diagramme entfernen, falls vorhanden
On Error Resume Next
Lastrow = Range("T" & Rows.Count).End(xlUp).Row
destinationSheet_3 = ActiveSheet.Name
'eingebettetes Diagramm 3 als Objekt zuweisen
Set Chart3 = Charts.Add
Set Chart3 = Chart3.Location(Where:=xlLocationAsObject, Name:=destinationSheet_3)
Set CHT_3 = ActiveChart.Parent
Set rngChart_3 = Range("N1:Y19")
With Chart3
'alle vorhandenen Datenreihen löschen, andernfalls werden die Datenreihen ergänzt
For i = .SeriesCollection.Count To 1 Step -1
.SeriesCollection(i).Delete
Next i
On Error GoTo 0
.ChartType = xlXYScatterLines ' make an XY chart
.SeriesCollection.NewSeries 'This creates the graph
With .SeriesCollection(1)
.XValues = Range("AA24:AA32,AB24:AB33,AC24:AC32,AD24:AD32,AE24:AE32,AF24:AF32,AG24:AG32,AH24:AH32,AI24:AI32,AJ24:AJ32") '
.Values = Range("T36:T" & Lastrow)
.MarkerStyle = xlMarkerStyleCircle
.MarkerSize = 7
.Format.Line.ForeColor.RGB = RGB(0, 32, 96) 'Change Plot Area border color
.Format.Fill.ForeColor.RGB = RGB(255, 0, 0) 'Change first bar chart series fill color
End With
.Parent.Name = "Chart 3"
.HasLegend = False
.HasTitle = True
With .ChartTitle
.Text = "Equilibrium curve"
.Characters.Font.Name = "Arial"
.Characters.Font.Color = RGB(0, 0, 128)
.Characters.Font.Size = 14
.Characters.Font.Bold = True
End With
With .Axes(xlCategory, xlPrimary)
.HasTitle = True
.AxisTitle.Characters.Text = "RH in %"
End With
With .Axes(xlValue, xlPrimary)
.HasTitle = True
.AxisTitle.Text = "dm in %"
End With
With .Axes(xlValue)
.MajorGridlines.Format.Line.ForeColor.RGB = RGB(91, 155, 213) 'Change Major gridline color
.TickLabels.Font.Color = RGB(91, 155, 213) 'Change Y-axis label color
End With
With .ChartArea.Format.TextFrame2.TextRange.Font
.Bold = msoTrue 'Make Font Bold
.Name = "Arial" 'Format Font Type
.Size = 12 'Format Font Size
End With
With Selection.Border
.ColorIndex = 5
.Weight = xlMedium
.LineStyle = xlContinuous
End With
.PlotArea.Format.Fill.ForeColor.RGB = RGB(255, 255, 200)
.ChartGroups(1).GapWidth = 60 'Adjust Bar Gap
End With
With CHT_3
.Left = rngChart_3.Left
.Top = rngChart_3.Top
.Width = rngChart_3.Width
.Height = rngChart_3.Height
End With
' Variable leeren
Set Chart3 = Nothing
' Reaktion auf Eingabe einschalten
Application.EnableEvents = True
' Bildschirmaktualisierung ein
Application.ScreenUpdating = True
End Sub
Farbe Das Diagramm mit mehreren Datenserien basierend auf Zellenfarbe mit VBA-Code
|