Ich habe den Code in Blatt 1 VBA-Fenster. Die Excel-Tabelle 1 in der Arbeitsmappe ist mit der Dropdown-Liste in Spalte C. Die 4 Optionen der Dropdown-Liste sind: Complete, Pending, Verpasste Deadline und Workable. Die Dropdown-Liste wird mithilfe von Blatt 2 erstellt und definiert die Methode name. Wenn ich jedoch den Wert "Complete" (Vollständig) anwähle, wird die Farbe für die gesamte Zeile nicht grün angezeigt. Wo gehe ich falsch?VBA Farbcodierung der gesamten Spalte nach Dropdown-Liste Wert
Private Sub Worksheet_Change(ByVal Target As Range)
'to make entire row green when job is workable
If Selection.Text = "Workable" Then
With ActiveCell
Range(Cells(.Row, .CurrentRegion.Column), Cells(.Row, .CurrentRegion.Columns.Count + .CurrentRegion.Column - 1)).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5287936
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End With
' to make entire row yellow when pending additonal information
ElseIf Selection.Text = "Pending" Then
With ActiveCell
Range(Cells(.Row, .CurrentRegion.Column), Cells(.Row, .CurrentRegion.Columns.Count + .CurrentRegion.Column - 1)).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End With
'to make entire row red when job is not workable
ElseIf Selection.Text = "Missed Deadline" Then
With ActiveCell
Range(Cells(.Row, .CurrentRegion.Column), Cells(.Row, .CurrentRegion.Columns.Count + .CurrentRegion.Column - 1)).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End With
'to make entire row light blue when job is complete
ElseIf Selection.Text = "Complete" Then
With ActiveCell
Range(Cells(.Row, .CurrentRegion.Column), Cells(.Row, .CurrentRegion.Columns.Count + .CurrentRegion.Column - 1)).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent1
.TintAndShade = 0.799981688894314
.PatternTintAndShade = 0
End With
End With
MsgBox "AWESOME!YOU DID IT!"
End If
End Sub
Bitte sehen Code und freundlich helfen. Ich danke dir sehr!
Sie möchten nur die ganze Zeile ändern? Verwenden Sie 'EntireRow' und verwenden Sie' Target' anstatt 'Selection'. – SJR
@SJR Nein, der 'Bereich (Zellen (.Row, .CurrentRegion.Column), Zellen (.Row, .CurrentRegion.Columns.Count + .CurrentRegion.Column - 1)). Wählen Sie den Operator aus, der die gewünschte Region auswählt. – Eugene
@Eugene - Ich denke, es gibt auch bessere Möglichkeiten, das zu tun. – SJR